home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / gdb / mipsread.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-07  |  82.8 KB  |  2,990 lines

  1. /* Read a symbol table in MIPS' format (Third-Eye).
  2.    Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  3.    Contributed by Alessandro Forin (af@cs.cmu.edu) at CMU.  Major
  4.    work by Per Bothner and John Gilmore at Cygnus Support.
  5.  
  6. This file is part of GDB.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. /* This module provides three functions: mipscoff_symfile_init,
  23.    which initializes to read a symbol file; mipscoff_new_init, which 
  24.    discards existing cached information when all symbols are being
  25.    discarded; and mipscoff_symfile_read, which reads a symbol table
  26.    from a file.
  27.  
  28.    mipscoff_symfile_read only does the minimum work necessary for letting the
  29.    user "name" things symbolically; it does not read the entire symtab.
  30.    Instead, it reads the external and static symbols and puts them in partial
  31.    symbol tables.  When more extensive information is requested of a
  32.    file, the corresponding partial symbol table is mutated into a full
  33.    fledged symbol table by going back and reading the symbols
  34.    for real.  mipscoff_psymtab_to_symtab() is called indirectly through
  35.    a pointer in the psymtab to do this.
  36.  
  37.    ECOFF symbol tables are mostly written in the byte order of the
  38.    target machine.  However, one section of the table (the auxiliary
  39.    symbol information) is written in the host byte order.  There is a
  40.    bit in the other symbol info which describes which host byte order
  41.    was used.  ECOFF thereby takes the trophy from Intel `b.out' for
  42.    the most brain-dead adaptation of a file format to byte order.
  43.  
  44.    This module can read all four of the known byte-order combinations,
  45.    on any type of host.  However, it does make (and check) the assumption
  46.    that the external form of a symbol table structure (on disk) 
  47.    occupies the same number of bytes as the internal form (in a struct).
  48.    Fixing this is possible but requires larger structural changes.  */
  49.  
  50. #define    TM_FILE_OVERRIDE
  51. #include "defs.h"
  52. #include "tm-mips.h"
  53. #include "symtab.h"
  54. #include "gdbtypes.h"
  55. #include "gdbcore.h"
  56. #include "symfile.h"
  57. #include "objfiles.h"
  58. #include "obstack.h"
  59. #include "buildsym.h"
  60.  
  61. #ifdef USG
  62. #include <sys/types.h>
  63. #define L_SET 0
  64. #define L_INCR 1
  65. #endif
  66.  
  67. #include <sys/param.h>
  68. #include <sys/file.h>
  69. #include <sys/stat.h>
  70.  
  71. #include "coff/mips.h"
  72. #include "coff/sym.h"
  73. #include "coff/symconst.h"
  74.  
  75. #include "libaout.h"        /* FIXME Secret internal BFD stuff for a.out */
  76. #include "aout/aout64.h"
  77. #include "aout/stab_gnu.h"    /* We always use GNU stabs, not native, now */
  78. #include "coff/ecoff-ext.h"
  79.  
  80. struct coff_exec {
  81.     struct external_filehdr f;
  82.     struct external_aouthdr a;
  83. };
  84.  
  85. /* These must match the corresponding definition in gcc/config/xm-mips.h.
  86.    At some point, these should probably go into a shared include file,
  87.    but currently gcc and gdb do not share any directories. */
  88.  
  89. #define CODE_MASK 0x8F300
  90. #define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
  91. #define MIPS_MARK_STAB(code) ((code)+CODE_MASK)
  92. #define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK)
  93. #define STABS_SYMBOL "@stabs"
  94.  
  95. /* Each partial symbol table entry contains a pointer to private data for the
  96.    read_symtab() function to use when expanding a partial symbol table entry
  97.    to a full symbol table entry.
  98.  
  99.    For mipsread this structure contains the index of the FDR that this psymtab
  100.    represents and a pointer to the symbol table header HDRR from the symbol
  101.    file that the psymtab was created from.  */
  102.  
  103. #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
  104. #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
  105. #define CUR_HDR(p) (PST_PRIVATE(p)->cur_hdr)
  106.  
  107. struct symloc {
  108.   int fdr_idx;
  109.   HDRR *cur_hdr;
  110.   EXTR **extern_tab; /* Pointer to external symbols for this file. */
  111.   int extern_count; /* Size of extern_tab. */
  112. };
  113.  
  114. /* Things we import explicitly from other modules */
  115.  
  116. extern int         info_verbose;
  117. extern struct block *block_for_pc();
  118. extern void         sort_symtab_syms();
  119.  
  120. /* Various complaints about symbol reading that don't abort the process */
  121.    
  122. struct complaint bad_file_number_complaint = 
  123.     {"bad file number %d", 0, 0};
  124.  
  125. struct complaint unknown_ext_complaint = 
  126.     {"unknown external symbol %s", 0, 0};
  127.  
  128. struct complaint unknown_sym_complaint = 
  129.     {"unknown local symbol %s", 0, 0};
  130.  
  131. struct complaint unknown_st_complaint = 
  132.     {"with type %d", 0, 0};
  133.  
  134. struct complaint block_overflow_complaint = 
  135.     {"block containing %s overfilled", 0, 0};
  136.  
  137. struct complaint basic_type_complaint = 
  138.     {"cannot map MIPS basic type 0x%x", 0, 0};
  139.  
  140. struct complaint unknown_type_qual_complaint = 
  141.     {"unknown type qualifier 0x%x", 0, 0};
  142.  
  143. struct complaint array_bitsize_complaint = 
  144.     {"size of array target type not known, assuming %d bits", 0, 0};
  145.  
  146. struct complaint bad_tag_guess_complaint = 
  147.     {"guessed tag type incorrectly", 0, 0};
  148.  
  149. /* Macros and extra defs */
  150.  
  151. /* Already-parsed symbols are marked specially */
  152.  
  153. #define stParsed stType
  154.  
  155. /* Puns: hard to find whether -g was used and how */
  156.  
  157. #define MIN_GLEVEL GLEVEL_0
  158. #define compare_glevel(a,b)                    \
  159.     (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) :            \
  160.      ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
  161.  
  162. /* When looking at .o files, avoid tripping over bad addresses */
  163.  
  164. #define SAFE_TEXT_ADDR 0x400000
  165. #define SAFE_DATA_ADDR 0x10000000
  166.  
  167. #define UNSAFE_DATA_ADDR(p)    ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
  168.  
  169. /* Things that really are local to this module */
  170.  
  171. /* GDB symtable for the current compilation unit */
  172.  
  173. static struct symtab *cur_stab;
  174.  
  175. /* MIPS symtab header for the current file */
  176.  
  177. static HDRR    *cur_hdr;
  178.  
  179. /* Pointer to current file decriptor record, and its index */
  180.  
  181. static FDR    *cur_fdr;
  182. static int     cur_fd;
  183.  
  184. /* Index of current symbol */
  185.  
  186. static int     cur_sdx;
  187.  
  188. /* Note how much "debuggable" this image is.  We would like
  189.    to see at least one FDR with full symbols */
  190.  
  191. static max_gdbinfo;
  192. static max_glevel;
  193.  
  194. /* When examining .o files, report on undefined symbols */
  195.  
  196. static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
  197.  
  198. /* Pseudo symbol to use when putting stabs into the symbol table.  */
  199.  
  200. static char stabs_symbol[] = STABS_SYMBOL;
  201.  
  202. /* Extra builtin types */
  203.  
  204. struct type *builtin_type_complex;
  205. struct type *builtin_type_double_complex;
  206. struct type *builtin_type_fixed_dec;
  207. struct type *builtin_type_float_dec;
  208. struct type *builtin_type_string;
  209.  
  210. /* Forward declarations */
  211.  
  212. static void
  213. fixup_symtab PARAMS ((HDRR *, char *, int, bfd *));
  214.  
  215. static void
  216. read_mips_symtab PARAMS ((struct objfile *));
  217.  
  218. static void
  219. read_the_mips_symtab PARAMS ((bfd *, CORE_ADDR *));
  220.  
  221. static int
  222. upgrade_type PARAMS ((struct type **, int, union aux_ext *, int));
  223.  
  224. static void
  225. parse_partial_symbols PARAMS ((int, struct objfile *));
  226.  
  227. static int
  228. cross_ref PARAMS ((union aux_ext *, struct type **, enum type_code, char **,
  229.            int));
  230.  
  231. static void
  232. fixup_sigtramp PARAMS ((void));
  233.  
  234. static struct symbol *
  235. new_symbol PARAMS ((char *));
  236.  
  237. static struct type *
  238. new_type PARAMS ((char *));
  239.  
  240. static struct block *
  241. new_block PARAMS ((int));
  242.  
  243. static struct symtab *
  244. new_symtab PARAMS ((char *, int, int, struct objfile *));
  245.  
  246. static struct linetable *
  247. new_linetable PARAMS ((int));
  248.  
  249. static struct blockvector *
  250. new_bvect PARAMS ((int));
  251.  
  252. static struct type *
  253. parse_type PARAMS ((union aux_ext *, int *, int));
  254.  
  255. static struct symbol *
  256. mylookup_symbol PARAMS ((char *, struct block *, enum namespace,
  257.              enum address_class));
  258.  
  259. static struct block *
  260. shrink_block PARAMS ((struct block *, struct symtab *));
  261.  
  262. static PTR
  263. xzalloc PARAMS ((unsigned int));
  264.  
  265. static void
  266. sort_blocks PARAMS ((struct symtab *));
  267.  
  268. static int
  269. compare_blocks PARAMS ((const void *, const void *));
  270.  
  271. static struct partial_symtab *
  272. new_psymtab PARAMS ((char *, struct objfile *));
  273.  
  274. #if 0
  275. static struct partial_symtab *
  276. parse_fdr PARAMS ((int, int, struct objfile *));
  277. #endif
  278.  
  279. static void
  280. psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *));
  281.  
  282. static void
  283. add_block PARAMS ((struct block *, struct symtab *));
  284.  
  285. static void
  286. add_symbol PARAMS ((struct symbol *, struct block *));
  287.  
  288. static int
  289. add_line PARAMS ((struct linetable *, int, CORE_ADDR, int));
  290.  
  291. static struct linetable *
  292. shrink_linetable PARAMS ((struct linetable *));
  293.  
  294. static char *
  295. mips_next_symbol_text PARAMS ((void));
  296.  
  297. /* Things we export to other modules */
  298.  
  299. /* Address bounds for the signal trampoline in inferior, if any */
  300. /* FIXME:  Nothing really seems to use this.  Why is it here? */
  301.  
  302. CORE_ADDR sigtramp_address, sigtramp_end;
  303.  
  304. static void
  305. mipscoff_new_init (ignore)
  306.      struct objfile *ignore;
  307. {
  308. }
  309.  
  310. static void
  311. mipscoff_symfile_init (objfile)
  312.      struct objfile *objfile;
  313. {
  314.   if (objfile -> sym_private != NULL)
  315.     {
  316.       mfree (objfile -> md, objfile -> sym_private);
  317.     }
  318.   objfile -> sym_private = NULL;
  319. }
  320.  
  321. static void
  322. mipscoff_symfile_read (objfile, addr, mainline)
  323.      struct objfile *objfile;
  324.      CORE_ADDR addr;
  325.      int mainline;
  326. {
  327.   bfd *abfd = objfile -> obfd;
  328.  
  329.   init_minimal_symbol_collection ();
  330.   make_cleanup (discard_minimal_symbols, 0);
  331.  
  332.   /* Now that the executable file is positioned at symbol table,
  333.      process it and define symbols accordingly.  */
  334.  
  335.   read_mips_symtab(objfile);
  336.  
  337.   /* Install any minimal symbols that have been collected as the current
  338.      minimal symbols for this objfile. */
  339.  
  340.   install_minimal_symbols (objfile);
  341. }
  342.   
  343. /* Perform any local cleanups required when we are done with a particular
  344.    objfile.  I.E, we are in the process of discarding all symbol information
  345.    for an objfile, freeing up all memory held for it, and unlinking the
  346.    objfile struct from the global list of known objfiles. */
  347.  
  348. static void
  349. mipscoff_symfile_finish (objfile)
  350.      struct objfile *objfile;
  351. {
  352.   if (objfile -> sym_private != NULL)
  353.     {
  354.       mfree (objfile -> md, objfile -> sym_private);
  355.     }
  356.  
  357.   /* If we have a file symbol header lying around, blow it away.  */
  358.  
  359.   if (cur_hdr)
  360.     {
  361.       free ((PTR)cur_hdr);
  362.     }
  363.   cur_hdr = 0;
  364. }
  365.  
  366. /* Allocate zeroed memory */
  367.  
  368. static PTR
  369. xzalloc(size)
  370.      unsigned int size;
  371. {
  372.     PTR p = xmalloc(size);
  373.  
  374.     memset(p, 0, size);
  375.     return p;
  376. }
  377.  
  378. /* Exported procedure: Builds a symtab from the PST partial one.
  379.    Restores the environment in effect when PST was created, delegates
  380.    most of the work to an ancillary procedure, and sorts
  381.    and reorders the symtab list at the end */
  382.  
  383. static void
  384. mipscoff_psymtab_to_symtab(pst)
  385.     struct partial_symtab *pst;
  386. {
  387.  
  388.     if (!pst)
  389.         return;
  390.  
  391.     if (info_verbose) {
  392.         printf_filtered("Reading in symbols for %s...", pst->filename);
  393.         fflush(stdout);
  394.     }
  395.     /* Restore the header and list of pending typedefs */
  396.     cur_hdr = CUR_HDR(pst);
  397.  
  398.     next_symbol_text_func = mips_next_symbol_text;
  399.  
  400.     psymtab_to_symtab_1(pst, pst->filename);
  401.  
  402.     /* Match with global symbols.  This only needs to be done once,
  403.        after all of the symtabs and dependencies have been read in.   */
  404.     scan_file_globals (pst->objfile);
  405.  
  406.     if (info_verbose)
  407.         printf_filtered("done.\n");
  408. }
  409.  
  410. /* Exported procedure: Is PC in the signal trampoline code */
  411.  
  412. int
  413. in_sigtramp(pc, ignore)
  414.     CORE_ADDR pc;
  415.     char *ignore;        /* function name */
  416. {
  417.     if (sigtramp_address == 0)
  418.         fixup_sigtramp();
  419.     return (pc >= sigtramp_address && pc < sigtramp_end);
  420. }
  421.  
  422. /* File-level interface functions */
  423.  
  424. /* Read the symtab information from file ABFD into memory.  Also,
  425.    return address just past end of our text segment in *END_OF_TEXT_SEGP.  */
  426.  
  427. static void
  428. read_the_mips_symtab(abfd, end_of_text_segp)
  429.     bfd        *abfd;
  430.     CORE_ADDR    *end_of_text_segp;
  431. {
  432.     int             stsize, st_hdrsize;
  433.     unsigned        st_filptr;
  434.     struct hdr_ext    hdr_ext;
  435.     HDRR            st_hdr;
  436.     /* Header for executable/object file we read symbols from */
  437.     struct coff_exec filhdr;
  438.     int val;
  439.  
  440.     /* We need some info from the initial headers */
  441.     val = bfd_seek(abfd, 0L, L_SET);
  442.     val = bfd_read((PTR)&filhdr, sizeof filhdr, 1, abfd);
  443.  
  444.     if (end_of_text_segp)
  445.         *end_of_text_segp =
  446.             bfd_h_get_32 (abfd, filhdr.a.text_start) +
  447.             bfd_h_get_32 (abfd, filhdr.a.tsize);
  448.  
  449.     /* Find and read the symbol table header */
  450.     st_hdrsize = bfd_h_get_32 (abfd, filhdr.f.f_nsyms);
  451.     st_filptr  = bfd_h_get_32 (abfd, filhdr.f.f_symptr);
  452.     if (st_filptr == 0)
  453.         return;
  454.  
  455.     bfd_seek (abfd, st_filptr, L_SET);
  456.     if (st_hdrsize != sizeof (hdr_ext)) {    /* Profanity check */
  457.         error ("Wrong header size: %d, not %d", st_hdrsize,
  458.             sizeof (hdr_ext));
  459.     }
  460.     if (bfd_read((PTR)&hdr_ext, st_hdrsize, 1, abfd) != st_hdrsize)
  461.         goto readerr;
  462.     ecoff_swap_hdr_in (abfd, &hdr_ext, &st_hdr);
  463.  
  464.     /* Find out how large the symbol table is */
  465.     stsize = (st_hdr.cbExtOffset - (st_filptr + st_hdrsize))
  466.         + st_hdr.iextMax * cbEXTR;
  467.  
  468.     /* Allocate space for the symbol table.  Read it in.  */
  469.     cur_hdr = (HDRR *) xmalloc(stsize + st_hdrsize);
  470.  
  471.     memcpy((PTR)cur_hdr, (PTR)&hdr_ext, st_hdrsize);
  472.     if (bfd_read((char *)cur_hdr + st_hdrsize, stsize, 1, abfd) != stsize)
  473.         goto readerr;
  474.  
  475.     /* Fixup file_pointers in it */
  476.     fixup_symtab(cur_hdr, (char *) cur_hdr + st_hdrsize,
  477.              st_filptr + st_hdrsize, abfd);
  478.  
  479.     return;
  480. readerr:
  481.     error("Short read on %s", bfd_get_filename (abfd));
  482. }
  483.  
  484.  
  485. /* Turn all file-relative pointers in the symtab described by HDR
  486.    into memory pointers, given that the symtab itself is located
  487.    at DATA in memory and F_PTR in the file.
  488.  
  489.    Byte-swap all the data structures, in place, while we are at it --
  490.    except AUX entries, which we leave in their original byte order.
  491.    They will be swapped as they are used instead.  (FIXME:  we ought to
  492.    do all the data structures that way.)  */
  493.  
  494. static void
  495. fixup_symtab (hdr, data, f_ptr, abfd)
  496.     HDRR *hdr;
  497.     char *data;
  498.     int f_ptr;
  499.     bfd *abfd;
  500. {
  501.     int             f_idx, s_idx, i;
  502.     FDR            *fh;
  503.     SYMR           *sh;
  504.     PDR           *pr;
  505.     EXTR           *esh;
  506.     struct rfd_ext *rbase;
  507.  
  508.     /* This function depends on the external and internal forms
  509.        of the MIPS symbol table taking identical space.  Check this
  510.        assumption at compile-time.  */
  511.     static check_hdr1[1 + sizeof (struct hdr_ext) - sizeof (HDRR)] = {0};
  512.     static check_hdr2[1 + sizeof (HDRR) - sizeof (struct hdr_ext)] = {0};
  513.     static check_fdr1[1 + sizeof (struct fdr_ext) - sizeof (FDR)] = {0};
  514.     static check_fdr2[1 + sizeof (FDR) - sizeof (struct fdr_ext)] = {0};
  515.     static check_pdr1[1 + sizeof (struct pdr_ext) - sizeof (PDR)] = {0};
  516.     static check_pdr2[1 + sizeof (PDR) - sizeof (struct pdr_ext)] = {0};
  517.     static check_sym1[1 + sizeof (struct sym_ext) - sizeof (SYMR)] = {0};
  518.     static check_sym2[1 + sizeof (SYMR) - sizeof (struct sym_ext)] = {0};
  519.     static check_ext1[1 + sizeof (struct ext_ext) - sizeof (EXTR)] = {0};
  520.     static check_ext2[1 + sizeof (EXTR) - sizeof (struct ext_ext)] = {0};
  521.     static check_rfd1[1 + sizeof (struct rfd_ext) - sizeof (RFDT)] = {0};
  522.     static check_rfd2[1 + sizeof (RFDT) - sizeof (struct rfd_ext)] = {0};
  523.  
  524.     /* Swap in the header record.  */
  525.     ecoff_swap_hdr_in (abfd, hdr, hdr);
  526.  
  527.     /*
  528.      * These fields are useless (and empty) by now:
  529.      *    hdr->cbDnOffset, hdr->cbOptOffset
  530.      * We use them for other internal purposes.
  531.      */
  532.     hdr->cbDnOffset = 0;
  533.     hdr->cbOptOffset = 0;
  534.  
  535. #define FIX(off) \
  536.         if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
  537.  
  538.         FIX(cbLineOffset);
  539.         FIX(cbPdOffset);
  540.         FIX(cbSymOffset);
  541.         FIX(cbOptOffset);
  542.         FIX(cbAuxOffset);
  543.         FIX(cbSsOffset);
  544.         FIX(cbSsExtOffset);
  545.         FIX(cbFdOffset);
  546.         FIX(cbRfdOffset);
  547.         FIX(cbExtOffset);
  548. #undef    FIX
  549.  
  550.     /* Fix all the RFD's.  */
  551.     rbase = (struct rfd_ext *)(hdr->cbRfdOffset);
  552.     for (i = 0; i < hdr->crfd; i++) {
  553.       ecoff_swap_rfd_in (abfd, rbase+i, (pRFDT) rbase+i);
  554.     }
  555.  
  556.     /* Fix all string pointers inside the symtab, and
  557.        the FDR records.  Also fix other miscellany.  */
  558.  
  559.     for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
  560.         register unsigned code_offset;
  561.  
  562.         /* Header itself, and strings */
  563.         fh = (FDR *) (hdr->cbFdOffset) + f_idx;
  564.  
  565.         /* Swap in the FDR */
  566.         ecoff_swap_fdr_in (abfd, fh, fh);
  567.  
  568.         fh->issBase += hdr->cbSsOffset;
  569.         if (fh->rss != -1)
  570.             fh->rss = (long)fh->rss + fh->issBase;
  571.  
  572.         /* Local symbols */
  573.         fh->isymBase = (int)((SYMR*)(hdr->cbSymOffset)+fh->isymBase);
  574.  
  575.         /* FIXME! Probably don't want to do this here! */
  576.         for (s_idx = 0; s_idx < fh->csym; s_idx++) {
  577.             sh = (SYMR*)fh->isymBase + s_idx;
  578.             ecoff_swap_sym_in (abfd, sh, sh);
  579.  
  580.             sh->iss = (long) sh->iss + fh->issBase;
  581.             sh->reserved = 0;
  582.         }
  583.  
  584.         cur_fd = f_idx;
  585.  
  586.         /* cannot fix fh->ipdFirst because it is a short */
  587. #define IPDFIRST(h,fh) \
  588.         ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
  589.  
  590.         /* Optional symbols (actually used for partial_symtabs) */
  591.         fh->ioptBase = 0;
  592.         fh->copt = 0;
  593.  
  594.         /* Aux symbols */
  595.         if (fh->caux)
  596.             fh->iauxBase = hdr->cbAuxOffset + fh->iauxBase * sizeof(union aux_ext);
  597.         /* Relative file descriptor table */
  598.         fh->rfdBase = hdr->cbRfdOffset + fh->rfdBase * sizeof(RFDT);
  599.  
  600.         /* Line numbers */
  601.         if (fh->cbLine)
  602.             fh->cbLineOffset += hdr->cbLineOffset;
  603.  
  604.         /* Procedure symbols.  (XXX This should be done later) */
  605.         code_offset = fh->adr;
  606.         for (s_idx = 0; s_idx < fh->cpd; s_idx++) {
  607.             unsigned name, only_ext;
  608.  
  609.             pr = (PDR*)(IPDFIRST(hdr,fh)) + s_idx;
  610.             ecoff_swap_pdr_in (abfd, pr, pr);
  611.  
  612.             /* Simple rule to find files linked "-x" */
  613.             only_ext = fh->rss == -1;
  614.             if (only_ext) {
  615.                 if (pr->isym == -1) {
  616.                     /* static function */
  617.                     sh = (SYMR*)-1;
  618.                 } else {
  619.                     /* external */
  620.                     name = hdr->cbExtOffset + pr->isym * sizeof(EXTR);
  621.                     sh = &((EXTR*)name)->asym;
  622.                 }
  623.             } else {
  624.                 /* Full symbols */
  625.                 sh = (SYMR*)fh->isymBase + pr->isym;
  626.                 /* Included code ? */
  627.                 if (s_idx == 0 && pr->adr != 0)
  628.                     code_offset -= pr->adr;
  629.             }
  630.  
  631.             /* Turn index into a pointer */
  632.             pr->isym = (long)sh;
  633.  
  634.             /* Fix line numbers */
  635.             pr->cbLineOffset += fh->cbLineOffset;
  636.  
  637.             /* Relocate address */
  638.             if (!only_ext)
  639.                 pr->adr += code_offset;
  640.         }        
  641.     }
  642.  
  643.     /* External symbols: swap in, and fix string */
  644.     for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
  645.         esh = (EXTR*)(hdr->cbExtOffset) + s_idx;
  646.         ecoff_swap_ext_in (abfd, esh, esh);
  647.         esh->asym.iss = esh->asym.iss + hdr->cbSsExtOffset;
  648.     }
  649. }
  650.  
  651.  
  652. /* Find a file descriptor given its index RF relative to a file CF */
  653.  
  654. static FDR *
  655. get_rfd (cf, rf)
  656.     int cf, rf;
  657. {
  658.     register FDR   *f;
  659.  
  660.     f = (FDR *) (cur_hdr->cbFdOffset) + cf;
  661.     /* Object files do not have the RFD table, all refs are absolute */
  662.     if (f->rfdBase == 0)
  663.         return (FDR *) (cur_hdr->cbFdOffset) + rf;
  664.     cf = *((pRFDT) f->rfdBase + rf);
  665.     return (FDR *) (cur_hdr->cbFdOffset) + cf;
  666. }
  667.  
  668. /* Return a safer print NAME for a file descriptor */
  669.  
  670. static char *
  671. fdr_name(name)
  672.     char *name;
  673. {
  674.     if (name == (char *) -1)
  675.         return "<stripped file>";
  676.     if (UNSAFE_DATA_ADDR(name))
  677.         return "<NFY>";
  678.     return name;
  679. }
  680.  
  681.  
  682. /* Read in and parse the symtab of the file DESC. INCREMENTAL says
  683.    whether we are adding to the general symtab or not. 
  684.    FIXME:  INCREMENTAL is currently always zero, though it should not be. */
  685.  
  686. static void
  687. read_mips_symtab (objfile)
  688.     struct objfile *objfile;
  689. {
  690.     CORE_ADDR end_of_text_seg;
  691.  
  692.     read_the_mips_symtab(objfile->obfd, &end_of_text_seg);
  693.  
  694.     parse_partial_symbols(end_of_text_seg, objfile);
  695.  
  696. #if 0
  697.     /*
  698.      * Check to make sure file was compiled with -g.
  699.      * If not, warn the user of this limitation.
  700.      */
  701.     if (compare_glevel(max_glevel, GLEVEL_2) < 0) {
  702.         if (max_gdbinfo == 0)
  703.             printf (
  704. "\n%s not compiled with -g, debugging support is limited.\n",
  705.                 objfile->name);
  706.         printf(
  707. "You should compile with -g2 or -g3 for best debugging support.\n");
  708.         fflush(stdout);
  709.     }
  710. #endif
  711. }
  712.  
  713. /* Local utilities */
  714.  
  715. /* Map of FDR indexes to partial symtabs */
  716.  
  717. struct pst_map {
  718.     struct partial_symtab *pst;    /* the psymtab proper */
  719.     int n_globals; /* exported globals (external symbols) */
  720.     int globals_offset;  /* cumulative */
  721. };
  722.  
  723.  
  724. /* Utility stack, used to nest procedures and blocks properly.
  725.    It is a doubly linked list, to avoid too many alloc/free.
  726.    Since we might need it quite a few times it is NOT deallocated
  727.    after use. */
  728.  
  729. static struct parse_stack {
  730.     struct parse_stack    *next, *prev;
  731.     struct symtab    *cur_st;    /* Current symtab. */
  732.     struct block    *cur_block;    /* Block in it. */
  733.     int             blocktype;    /* What are we parsing. */
  734.     int             maxsyms;    /* Max symbols in this block. */
  735.     struct type        *cur_type;    /* Type we parse fields for. */
  736.     int             cur_field;    /* Field number in cur_type. */
  737.     int             procadr;    /* Start addres of this procedure */
  738.     int             numargs;    /* Its argument count */
  739. } *top_stack;    /* Top stack ptr */
  740.  
  741.  
  742. /* Enter a new lexical context */
  743.  
  744. static void
  745. push_parse_stack()
  746. {
  747.     struct parse_stack *new;
  748.  
  749.     /* Reuse frames if possible */
  750.     if (top_stack && top_stack->prev)
  751.         new = top_stack->prev;
  752.     else
  753.         new = (struct parse_stack *) xzalloc(sizeof(struct parse_stack));
  754.     /* Initialize new frame with previous content */
  755.     if (top_stack) {
  756.         register struct parse_stack *prev = new->prev;
  757.  
  758.         *new = *top_stack;
  759.         top_stack->prev = new;
  760.         new->prev = prev;
  761.         new->next = top_stack;
  762.     }
  763.     top_stack = new;
  764. }
  765.  
  766. /* Exit a lexical context */
  767.  
  768. static void
  769. pop_parse_stack()
  770. {
  771.     if (!top_stack)
  772.         return;
  773.     if (top_stack->next)
  774.         top_stack = top_stack->next;
  775. }
  776.  
  777.  
  778. /* Cross-references might be to things we haven't looked at
  779.    yet, e.g. type references.  To avoid too many type
  780.    duplications we keep a quick fixup table, an array
  781.    of lists of references indexed by file descriptor */
  782.  
  783. static struct mips_pending {
  784.     struct mips_pending    *next;        /* link */
  785.     SYMR        *s;        /* the symbol */
  786.     struct type    *t;        /* its partial type descriptor */
  787. } **pending_list;
  788.  
  789.  
  790. /* Check whether we already saw symbol SH in file FH as undefined */
  791.  
  792. static struct mips_pending *
  793. is_pending_symbol(fh, sh)
  794.     FDR *fh;
  795.     SYMR *sh;
  796. {
  797.     int             f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
  798.     register struct mips_pending *p;
  799.  
  800.     /* Linear search is ok, list is typically no more than 10 deep */
  801.     for (p = pending_list[f_idx]; p; p = p->next)
  802.         if (p->s == sh)
  803.             break;
  804.     return p;
  805. }
  806.  
  807. /* Add a new undef symbol SH of type T */
  808.  
  809. static void
  810. add_pending(fh, sh, t)
  811.     FDR *fh;
  812.     SYMR *sh;
  813.     struct type *t;
  814. {
  815.     int             f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
  816.     struct mips_pending *p = is_pending_symbol(fh, sh);
  817.  
  818.     /* Make sure we do not make duplicates */
  819.     if (!p) {
  820.         p = (struct mips_pending *) xmalloc(sizeof(*p));
  821.         p->s = sh;
  822.         p->t = t;
  823.         p->next = pending_list[f_idx];
  824.         pending_list[f_idx] = p;
  825.     }
  826.     sh->reserved = 1;    /* for quick check */
  827. }
  828.  
  829. /* Throw away undef entries when done with file index F_IDX */
  830. /* FIXME -- storage leak.  This is never called!!!   --gnu */
  831.  
  832. static void
  833. free_pending(f_idx)
  834.     int f_idx;
  835. {
  836.     register struct mips_pending *p, *q;
  837.  
  838.     for (p = pending_list[f_idx]; p; p = q) {
  839.         q = p->next;
  840.         free((PTR)p);
  841.     }
  842.     pending_list[f_idx] = 0;
  843. }
  844.  
  845. static char *
  846. prepend_tag_kind(tag_name, type_code)
  847.      char *tag_name;
  848.      enum type_code type_code;
  849. {
  850.     char *prefix;
  851.     char *result;
  852.     switch (type_code) {
  853.       case TYPE_CODE_ENUM:
  854.     prefix = "enum ";
  855.     break;
  856.       case TYPE_CODE_STRUCT:
  857.     prefix = "struct ";
  858.     break;
  859.       case TYPE_CODE_UNION:
  860.     prefix = "union ";
  861.     break;
  862.       default:
  863.     prefix = "";
  864.     }
  865.  
  866.     result = (char*)obstack_alloc (¤t_objfile->symbol_obstack,
  867.                    strlen(prefix) + strlen(tag_name) + 1);
  868.     sprintf(result, "%s%s", prefix, tag_name);
  869.     return result;
  870. }
  871.  
  872.  
  873. /* Parsing Routines proper. */
  874.  
  875. /* Parse a single symbol. Mostly just make up a GDB symbol for it.
  876.    For blocks, procedures and types we open a new lexical context.
  877.    This is basically just a big switch on the symbol's type.
  878.    Argument AX is the base pointer of aux symbols for this file (fh->iauxBase).
  879.    BIGEND says whether aux symbols are big-endian or little-endian.
  880.    Return count of SYMR's handled (normally one). */
  881.  
  882. static int
  883. parse_symbol(sh, ax, bigend)
  884.     SYMR *sh;
  885.     union aux_ext *ax;
  886.     int bigend;
  887. {
  888.     char *name;
  889.     struct symbol  *s;
  890.     struct block   *b;
  891.     struct type    *t;
  892.     struct field   *f;
  893.     int count = 1;
  894.     /* When a symbol is cross-referenced from other files/symbols
  895.        we mark it explicitly */
  896.     int             pend = (sh->reserved == 1);
  897.     enum address_class class;
  898.     TIR        tir;
  899.  
  900.     switch (sh->st) {
  901.  
  902.         case stNil:
  903.         break;
  904.  
  905.         case stGlobal:    /* external symbol, goes into global block */
  906.         class = LOC_STATIC;
  907.         b = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
  908.                       GLOBAL_BLOCK);
  909.         s = new_symbol((char *)sh->iss);
  910.         SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
  911.         goto data;
  912.  
  913.         case stStatic:    /* static data, goes into current block. */
  914.         class = LOC_STATIC;
  915.         b = top_stack->cur_block;
  916.         s = new_symbol((char *)sh->iss);
  917.         SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
  918.         goto data;
  919.  
  920.         case stLocal:    /* local variable, goes into current block */
  921.         if (sh->sc == scRegister) {
  922.             class = LOC_REGISTER;
  923.             if (sh->value > 31)
  924.                 sh->value += FP0_REGNUM-32;
  925.         } else
  926.             class = LOC_LOCAL;
  927.         b = top_stack->cur_block;
  928.         s = new_symbol((char *)sh->iss);
  929.         SYMBOL_VALUE(s) = sh->value;
  930.  
  931. data:        /* Common code for symbols describing data */
  932.         SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
  933.         SYMBOL_CLASS(s) = class;
  934.         add_symbol(s, b);
  935.  
  936.         /* Type could be missing in a number of cases */
  937.         if (sh->sc == scUndefined || sh->sc == scNil ||
  938.             sh->index == 0xfffff)
  939.             SYMBOL_TYPE(s) = builtin_type_int;    /* undefined? */
  940.         else
  941.             SYMBOL_TYPE(s) = parse_type(ax + sh->index, 0, bigend);
  942.         /* Value of a data symbol is its memory address */
  943.         break;
  944.  
  945.         case stParam:    /* arg to procedure, goes into current block */
  946.         max_gdbinfo++;
  947.         top_stack->numargs++;
  948.  
  949.         name = (char*)sh->iss;
  950.         /* Special GNU C++ name.  */
  951.         if (name[0] == CPLUS_MARKER && name[1] == 't' && name[2] == 0)
  952.             name = "this";
  953.         s = new_symbol(name);
  954.  
  955.         SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
  956.         if (sh->sc == scRegister) {
  957.             SYMBOL_CLASS(s) = LOC_REGPARM;
  958.             if (sh->value > 31)
  959.                 sh->value += FP0_REGNUM-32;
  960.         } else
  961.             SYMBOL_CLASS(s) = LOC_ARG;
  962.         SYMBOL_VALUE(s) = sh->value;
  963.         SYMBOL_TYPE(s) = parse_type(ax + sh->index, 0, bigend);
  964.         add_symbol(s, top_stack->cur_block);
  965. #if 0
  966.         /* FIXME:  This has not been tested.  See dbxread.c */
  967.         /* Add the type of this parameter to the function/procedure
  968.            type of this block. */
  969.         add_param_to_type(&top_stack->cur_block->function->type,s);
  970. #endif
  971.         break;
  972.  
  973.         case stLabel:    /* label, goes into current block */
  974.         s = new_symbol((char *)sh->iss);
  975.         SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;    /* so that it can be used */
  976.         SYMBOL_CLASS(s) = LOC_LABEL;        /* but not misused */
  977.         SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
  978.         SYMBOL_TYPE(s) = builtin_type_int;
  979.         add_symbol(s, top_stack->cur_block);
  980.         break;
  981.  
  982.         case stProc:    /* Procedure, usually goes into global block */
  983.         case stStaticProc:    /* Static procedure, goes into current block */
  984.         s = new_symbol((char *)sh->iss);
  985.         SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
  986.         SYMBOL_CLASS(s) = LOC_BLOCK;
  987.         /* Type of the return value */
  988.         if (sh->sc == scUndefined || sh->sc == scNil)
  989.             t = builtin_type_int;
  990.         else
  991.             t = parse_type(ax + sh->index + 1, 0, bigend);
  992.         b = top_stack->cur_block;
  993.         if (sh->st == stProc) {
  994.             struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
  995.             /* The next test should normally be true,
  996.                but provides a hook for nested functions
  997.                (which we don't want to make global). */
  998.             if (b == BLOCKVECTOR_BLOCK(bv, STATIC_BLOCK))
  999.             b = BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK);
  1000.         }
  1001.         add_symbol(s, b);
  1002.  
  1003.         /* Make a type for the procedure itself */
  1004. #if 0
  1005.         /* FIXME:  This has not been tested yet!  See dbxread.c */
  1006.         /* Generate a template for the type of this function.  The 
  1007.            types of the arguments will be added as we read the symbol 
  1008.            table. */
  1009.         bcopy(SYMBOL_TYPE(s),lookup_function_type(t),sizeof(struct type));
  1010. #else
  1011.         SYMBOL_TYPE(s) = lookup_function_type (t);
  1012. #endif
  1013.  
  1014.         /* Create and enter a new lexical context */
  1015.         b = new_block(top_stack->maxsyms);
  1016.         SYMBOL_BLOCK_VALUE(s) = b;
  1017.         BLOCK_FUNCTION(b) = s;
  1018.         BLOCK_START(b) = BLOCK_END(b) = sh->value;
  1019.         BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
  1020.         add_block(b, top_stack->cur_st);
  1021.  
  1022.         /* Not if we only have partial info */
  1023.         if (sh->sc == scUndefined || sh->sc == scNil)
  1024.             break;
  1025.  
  1026.         push_parse_stack();
  1027.         top_stack->cur_block = b;
  1028.         top_stack->blocktype = sh->st;
  1029.         top_stack->cur_type = SYMBOL_TYPE(s);
  1030.         top_stack->cur_field = -1;
  1031.         top_stack->procadr = sh->value;
  1032.         top_stack->numargs = 0;
  1033.  
  1034.         sh->value = (long) SYMBOL_TYPE(s);
  1035.         break;
  1036.  
  1037.  
  1038. #ifndef btVoid  /* btVoid was added late. */
  1039. #define btVoid 26
  1040. #endif                
  1041. /* These new symbol types have been recently added to SGI machines. */
  1042. #ifndef stStruct
  1043. #define stStruct 26
  1044. #endif
  1045. #ifndef stUnion
  1046. #define stUnion 27
  1047. #endif
  1048. #ifndef stEnum
  1049. #define stEnum 28
  1050. #endif
  1051.         case stStruct:
  1052.         case stUnion:
  1053.         case stEnum:
  1054.  
  1055.         case stBlock:    /* Either a lexical block, or some type */
  1056.         push_parse_stack();
  1057.         top_stack->blocktype = stBlock;
  1058.         if (sh->sc == scInfo) {    /* structure/union/enum def */
  1059.             enum type_code type_code =
  1060.                 sh->st == stStruct ? TYPE_CODE_STRUCT
  1061.               : sh->st == stUnion ? TYPE_CODE_UNION
  1062.               : sh->st == stEnum ? TYPE_CODE_ENUM
  1063.               : TYPE_CODE_UNDEF;
  1064.             int nfields = 0;
  1065.             SYMR *tsym;
  1066.             long max_value = 0;
  1067.             struct field *f;
  1068.  
  1069.             s = new_symbol((char *)sh->iss);
  1070.             SYMBOL_NAMESPACE(s) = STRUCT_NAMESPACE;
  1071.             SYMBOL_CLASS(s) = LOC_TYPEDEF;
  1072.             SYMBOL_VALUE(s) = 0;
  1073.             add_symbol(s, top_stack->cur_block);
  1074.  
  1075.             /* First count the number of fields. */
  1076.             for (tsym = sh+1; tsym->st != stEnd; tsym++)
  1077.             if (tsym->st == stMember) {
  1078.                 if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
  1079.                 /* If the type of the member is Nil (or Void)
  1080.                    assume the tag is an enumeration. */
  1081.                 if (tsym->index == indexNil)
  1082.                     type_code = TYPE_CODE_ENUM;
  1083.                 else {
  1084.                     ecoff_swap_tir_in (bigend,
  1085.                                &ax[tsym->index].a_ti,
  1086.                                &tir);
  1087.                     if (tir.bt == btNil || tir.bt == btVoid)
  1088.                     type_code = TYPE_CODE_ENUM;
  1089.                 }
  1090.                 nfields++;
  1091.                 if (tsym->value > max_value)
  1092.                 max_value = tsym->value;
  1093.             }
  1094.             else if (tsym->st == stBlock
  1095.                  || tsym->st == stUnion
  1096.                  || tsym->st == stEnum
  1097.                  || tsym->st == stStruct
  1098.                  || tsym->st == stParsed) {
  1099.                 if (tsym->sc == scVariant) ; /*UNIMPLEMENTED*/
  1100.                 if (tsym->index != 0)
  1101.                 tsym = ((SYMR*)cur_fdr->isymBase)
  1102.                     + tsym->index-1;
  1103.             }
  1104.             
  1105.             /* There is no guaranteed way to distinguish struct,
  1106.                unions, and enums at this point.  This is a bug in the
  1107.                original design (that has been fixed with the
  1108.                recent addition of the stStruct, stUnion, and stEnum
  1109.                symbol types.)  The way you can tell is if/when you
  1110.                see a variable or field of that type:  In that case
  1111.                the variable's type (in the AUX table) says if the
  1112.                type is struct, union, or enum,
  1113.                and points back to the stBlock here.
  1114.                So you can patch the tag kind up later - but only
  1115.                if there actually is a variable or field of that type.
  1116.  
  1117.                So until we know for sure, we will guess at this point.
  1118.                The heuristic is:
  1119.                If the first member has index==indexNil or a void type,
  1120.                assume we have an enumeration.
  1121.                Otherwise, if there is more than one member, and all
  1122.                the members have offset 0, assume we have a union.
  1123.                Otherwise, assume we have a struct.
  1124.  
  1125.                The heuristic could guess wrong in the case of
  1126.                of an enumeration with no members or a union
  1127.                with one (or zero) members, or when all except the
  1128.                last field of a struct have width zero.
  1129.                These are uncommon and/or illegal situations, and
  1130.                in any case guessing wrong probably doesn't matter much.
  1131.  
  1132.                But if we later do find out we were wrong,
  1133.                we fixup the tag kind.  Members of an enumeration
  1134.                must be handled differently from struct/union fields,
  1135.                and that is harder to patch up, but luckily we
  1136.                shouldn't need to.  (If there are any enumeration
  1137.                members, we can tell for sure it's an enum here.) */
  1138.  
  1139.             if (type_code == TYPE_CODE_UNDEF)
  1140.             if (nfields > 1 && max_value == 0)
  1141.               type_code = TYPE_CODE_UNION;
  1142.             else
  1143.               type_code = TYPE_CODE_STRUCT;
  1144.             
  1145.             /* If this type was expected, use its partial definition */
  1146.             if (pend)
  1147.             t = is_pending_symbol(cur_fdr, sh)->t;
  1148.             else
  1149.             t = new_type(prepend_tag_kind((char *)sh->iss,
  1150.                               type_code));
  1151.  
  1152.             TYPE_CODE(t) = type_code;
  1153.             TYPE_LENGTH(t) = sh->value;
  1154.             TYPE_NFIELDS(t) = nfields;
  1155.             TYPE_FIELDS(t) = f = (struct field*)
  1156.               obstack_alloc (¤t_objfile -> type_obstack,
  1157.                      nfields * sizeof (struct field));
  1158.             
  1159.             if (type_code == TYPE_CODE_ENUM) {
  1160.             /* This is a non-empty enum. */
  1161.             for (tsym = sh + 1; tsym->st == stMember; tsym++) {
  1162.                 struct symbol *enum_sym;
  1163.                 f->bitpos = tsym->value;
  1164.                 f->type = t;
  1165.                 f->name = (char*)tsym->iss;
  1166.                 f->bitsize = 0;
  1167.                 
  1168.                 enum_sym = (struct symbol *)
  1169.                 obstack_alloc (¤t_objfile->symbol_obstack,
  1170.                            sizeof (struct symbol));
  1171.                 memset ((PTR)enum_sym, 0, sizeof (struct symbol));
  1172.                 SYMBOL_NAME (enum_sym) = f->name;
  1173.                 SYMBOL_CLASS (enum_sym) = LOC_CONST;
  1174.                 SYMBOL_TYPE (enum_sym) = t;
  1175.                 SYMBOL_NAMESPACE (enum_sym) = VAR_NAMESPACE;
  1176.                 SYMBOL_VALUE (enum_sym) = tsym->value;
  1177.                 add_symbol(enum_sym, top_stack->cur_block);
  1178.                 
  1179.                 /* Skip the stMembers that we've handled. */
  1180.                 count++;
  1181.                 f++;
  1182.             }
  1183.             }
  1184.             SYMBOL_TYPE(s) = t;
  1185.             /* make this the current type */
  1186.             top_stack->cur_type = t;
  1187.             top_stack->cur_field = 0;
  1188.             /* Mark that symbol has a type, and say which one */
  1189.             sh->value = (long) t;
  1190.         } else {
  1191.             /* beginnning of (code) block. Value of symbol
  1192.                is the displacement from procedure start */
  1193.             b = new_block(top_stack->maxsyms);
  1194.             BLOCK_START(b) = sh->value + top_stack->procadr;
  1195.             BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
  1196.             top_stack->cur_block = b;
  1197.             add_block(b, top_stack->cur_st);
  1198.         }
  1199.         break;
  1200.  
  1201.         case stEnd:        /* end (of anything) */
  1202.         if (sh->sc == scInfo) {
  1203.             /* Finished with type */
  1204.             top_stack->cur_type = 0;
  1205.         } else if (sh->sc == scText &&
  1206.                (top_stack->blocktype == stProc ||
  1207.                 top_stack->blocktype == stStaticProc)) {
  1208.             /* Finished with procedure */
  1209.             struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
  1210.             struct mips_extra_func_info *e;
  1211.             struct block *b;
  1212.             int i;
  1213.  
  1214.             BLOCK_END(top_stack->cur_block) += sh->value; /* size */
  1215.  
  1216.             /* Make up special symbol to contain procedure specific
  1217.                info */
  1218.             s = new_symbol(".gdbinfo.");
  1219.             SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
  1220.             SYMBOL_CLASS(s) = LOC_CONST;
  1221.             SYMBOL_TYPE(s) = builtin_type_void;
  1222.             e = (struct mips_extra_func_info *)
  1223.               obstack_alloc (¤t_objfile->symbol_obstack,
  1224.                      sizeof (struct mips_extra_func_info));
  1225.             SYMBOL_VALUE(s) = (int)e;
  1226.             e->numargs = top_stack->numargs;
  1227.             add_symbol(s, top_stack->cur_block);
  1228.  
  1229.             /* Reallocate symbols, saving memory */
  1230.             b = shrink_block(top_stack->cur_block, top_stack->cur_st);
  1231.  
  1232.             /* f77 emits proc-level with address bounds==[0,0],
  1233.                So look for such child blocks, and patch them.  */
  1234.             for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++) {
  1235.             struct block *b_bad = BLOCKVECTOR_BLOCK(bv,i);
  1236.             if (BLOCK_SUPERBLOCK(b_bad) == b
  1237.              && BLOCK_START(b_bad) == top_stack->procadr
  1238.              && BLOCK_END(b_bad) == top_stack->procadr) {
  1239.                 BLOCK_START(b_bad) = BLOCK_START(b);
  1240.                 BLOCK_END(b_bad) = BLOCK_END(b);
  1241.             }
  1242.             }
  1243.         } else if (sh->sc == scText && top_stack->blocktype == stBlock) {
  1244.             /* End of (code) block. The value of the symbol
  1245.                is the displacement from the procedure`s start
  1246.                address of the end of this block. */
  1247.             BLOCK_END(top_stack->cur_block) = sh->value + top_stack->procadr;
  1248.             (void) shrink_block(top_stack->cur_block, top_stack->cur_st);
  1249.         }
  1250.         pop_parse_stack();    /* restore previous lexical context */
  1251.         break;
  1252.  
  1253.         case stMember:    /* member of struct or union */
  1254.         f = &TYPE_FIELDS(top_stack->cur_type)[top_stack->cur_field++];
  1255.         f->name = (char*)sh->iss;
  1256.         f->bitpos = sh->value;
  1257.         f->bitsize = 0;
  1258.         f->type = parse_type(ax + sh->index, &f->bitsize, bigend);
  1259.         break;
  1260.  
  1261.         case stTypedef:    /* type definition */
  1262.         s = new_symbol((char *)sh->iss);
  1263.         SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
  1264.         SYMBOL_CLASS(s) = LOC_TYPEDEF;
  1265.         SYMBOL_BLOCK_VALUE(s) = top_stack->cur_block;
  1266.         add_symbol(s, top_stack->cur_block);            
  1267.         SYMBOL_TYPE(s) = parse_type(ax + sh->index, 0, bigend);
  1268.         sh->value = (long) SYMBOL_TYPE(s);
  1269.         break;
  1270.  
  1271.         case stFile:    /* file name */
  1272.         push_parse_stack();
  1273.         top_stack->blocktype = sh->st;
  1274.         break;
  1275.  
  1276.         /* I`ve never seen these for C */
  1277.         case stRegReloc:
  1278.         break;        /* register relocation */
  1279.         case stForward:
  1280.         break;        /* forwarding address */
  1281.         case stConstant:
  1282.         break;        /* constant */
  1283.         default:
  1284.         error("Unknown symbol type %x.", sh->st);
  1285.     }
  1286.     sh->st = stParsed;
  1287.     return count;
  1288. }
  1289.  
  1290. /* Parse the type information provided in the raw AX entries for
  1291.    the symbol SH. Return the bitfield size in BS, in case.
  1292.    We must byte-swap the AX entries before we use them; BIGEND says whether
  1293.    they are big-endian or little-endian (from fh->fBigendian).  */
  1294.  
  1295. static struct type *
  1296. parse_type(ax, bs, bigend)
  1297.     union aux_ext    *ax;
  1298.     int    *bs;
  1299.     int    bigend;
  1300. {
  1301.     /* Null entries in this map are treated specially */
  1302.     static struct type **map_bt[] =
  1303.     {
  1304.          &builtin_type_void,        /* btNil */
  1305.          0,                /* btAdr */
  1306.          &builtin_type_char,        /* btChar */
  1307.          &builtin_type_unsigned_char,    /* btUChar */
  1308.          &builtin_type_short,        /* btShort */
  1309.          &builtin_type_unsigned_short,    /* btUShort */
  1310.          &builtin_type_int,        /* btInt */
  1311.          &builtin_type_unsigned_int,    /* btUInt */
  1312.          &builtin_type_long,        /* btLong */
  1313.          &builtin_type_unsigned_long,    /* btULong */
  1314.          &builtin_type_float,        /* btFloat */
  1315.          &builtin_type_double,        /* btDouble */
  1316.          0,                /* btStruct */
  1317.          0,                /* btUnion */
  1318.          0,                /* btEnum */
  1319.          0,                /* btTypedef */
  1320.          0,                /* btRange */
  1321.          0,                /* btSet */
  1322.          &builtin_type_complex,        /* btComplex */
  1323.          &builtin_type_double_complex,    /* btDComplex */
  1324.          0,                /* btIndirect */
  1325.          &builtin_type_fixed_dec,    /* btFixedDec */
  1326.          &builtin_type_float_dec,    /* btFloatDec */
  1327.          &builtin_type_string,        /* btString */
  1328.          0,                /* btBit */
  1329.          0,                /* btPicture */
  1330.          &builtin_type_void,        /* btVoid */
  1331.     };
  1332.  
  1333.     TIR            t[1];
  1334.     struct type    *tp = 0;
  1335.     char           *fmt;
  1336.     union aux_ext *tax;
  1337.     enum type_code type_code;
  1338.  
  1339.     /* Use aux as a type information record, map its basic type.  */
  1340.     tax = ax;
  1341.     ecoff_swap_tir_in (bigend, &tax->a_ti, t);
  1342.     if (t->bt > (sizeof (map_bt)/sizeof (*map_bt))) {
  1343.         complain (&basic_type_complaint, (char *)t->bt);
  1344.         return builtin_type_int;
  1345.     }
  1346.     if (map_bt[t->bt]) {
  1347.         tp = *map_bt[t->bt];
  1348.         fmt = "%s";
  1349.     } else {
  1350.             tp = NULL;
  1351.         /* Cannot use builtin types -- build our own */
  1352.         switch (t->bt) {
  1353.             case btAdr:
  1354.             tp = lookup_pointer_type (builtin_type_void);
  1355.             fmt = "%s";
  1356.             break;
  1357.             case btStruct:
  1358.             type_code = TYPE_CODE_STRUCT;
  1359.             fmt = "struct %s";
  1360.             break;
  1361.             case btUnion:
  1362.             type_code = TYPE_CODE_UNION;
  1363.             fmt = "union %s";
  1364.             break;
  1365.             case btEnum:
  1366.             type_code = TYPE_CODE_ENUM;
  1367.             fmt = "enum %s";
  1368.             break;
  1369.             case btRange:
  1370.             type_code = TYPE_CODE_RANGE;
  1371.             fmt = "%s";
  1372.             break;
  1373.             case btSet:
  1374.             type_code = TYPE_CODE_SET;
  1375.             fmt = "set %s";
  1376.             break;
  1377.             case btTypedef:
  1378.             default:
  1379.             complain (&basic_type_complaint, (char *)t->bt);
  1380.             return builtin_type_int;
  1381.         }
  1382.     }
  1383.  
  1384.     /* Skip over any further type qualifiers (FIXME).  */
  1385.     if (t->continued) {
  1386.         /* This is the way it would work if the compiler worked */
  1387.         TIR t1[1];
  1388.         do {
  1389.             ax++;
  1390.             ecoff_swap_tir_in (bigend, ax, t1);
  1391.         } while (t1->continued);
  1392.     }
  1393.  
  1394.     /* Move on to next aux */
  1395.     ax++;
  1396.  
  1397.     if (t->fBitfield) {
  1398.         *bs = AUX_GET_WIDTH (bigend, ax);
  1399.         ax++;
  1400.     }
  1401.  
  1402.     /* All these types really point to some (common) MIPS type
  1403.        definition, and only the type-qualifiers fully identify
  1404.        them.  We'll make the same effort at sharing. */
  1405.     if (t->bt == btIndirect ||
  1406.         t->bt == btStruct ||
  1407.         t->bt == btUnion ||
  1408.         t->bt == btEnum ||
  1409.         t->bt == btTypedef ||
  1410.         t->bt == btRange ||
  1411.         t->bt == btSet) {
  1412.         char            name[256], *pn;
  1413.  
  1414.         /* Try to cross reference this type */
  1415.         ax += cross_ref(ax, &tp, type_code, &pn, bigend);
  1416.         /* reading .o file ? */
  1417.         if (UNSAFE_DATA_ADDR(tp))
  1418.             tp = init_type(type_code, 0, 0, 0, (struct objfile *) NULL);
  1419.         /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
  1420.         sprintf(name, fmt, pn);
  1421.  
  1422.         /* Usually, TYPE_CODE(tp) is already type_code.  The main
  1423.            exception is if we guessed wrong re struct/union/enum. */
  1424.         if (TYPE_CODE(tp) != type_code) {
  1425.             complain (&bad_tag_guess_complaint, 0);
  1426.             TYPE_CODE(tp) = type_code;
  1427.         }
  1428.         if (TYPE_NAME(tp) == NULL || strcmp(TYPE_NAME(tp), name) != 0)
  1429.             TYPE_NAME(tp) = obsavestring(name, strlen(name),
  1430.                          ¤t_objfile -> type_obstack);
  1431.     }
  1432.  
  1433.     /* Deal with range types */
  1434.     if (t->bt == btRange) {
  1435.         TYPE_NFIELDS (tp) = 2;
  1436.         TYPE_FIELDS (tp) =
  1437.           (struct field *) obstack_alloc (¤t_objfile -> type_obstack,
  1438.                           2 * sizeof (struct field));
  1439.         TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"),
  1440.                             ¤t_objfile -> type_obstack);
  1441.         TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax);
  1442.         ax++;
  1443.         TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"),
  1444.                             ¤t_objfile -> type_obstack);
  1445.         TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax);
  1446.         ax++;
  1447.     }
  1448.  
  1449.     /* Parse all the type qualifiers now. If there are more
  1450.        than 6 the game will continue in the next aux */
  1451.  
  1452. #define PARSE_TQ(tq) \
  1453.     if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
  1454.  
  1455. again:    PARSE_TQ(tq0);
  1456.     PARSE_TQ(tq1);
  1457.     PARSE_TQ(tq2);
  1458.     PARSE_TQ(tq3);
  1459.     PARSE_TQ(tq4);
  1460.     PARSE_TQ(tq5);
  1461. #undef    PARSE_TQ
  1462.  
  1463.     if (t->continued) {
  1464.         tax++;
  1465.         ecoff_swap_tir_in (bigend, &tax->a_ti, t);
  1466.         goto again;
  1467.     }
  1468.     return tp;
  1469. }
  1470.  
  1471. /* Make up a complex type from a basic one.  Type is passed by
  1472.    reference in TPP and side-effected as necessary. The type
  1473.    qualifier TQ says how to handle the aux symbols at AX for
  1474.    the symbol SX we are currently analyzing.  BIGEND says whether
  1475.    aux symbols are big-endian or little-endian.
  1476.    Returns the number of aux symbols we parsed. */
  1477.  
  1478. static int
  1479. upgrade_type(tpp, tq, ax, bigend)
  1480.     struct type  **tpp;
  1481.     int           tq;
  1482.     union aux_ext *ax;
  1483.     int           bigend;
  1484. {
  1485.     int            off;
  1486.     struct type   *t;
  1487.  
  1488.     /* Used in array processing */
  1489.     int             rf, id;
  1490.     FDR            *fh;
  1491.     struct field   *f;
  1492.     int        lower, upper;
  1493.     RNDXR        rndx;
  1494.  
  1495.     switch (tq) {
  1496.     case tqPtr:
  1497.         t = lookup_pointer_type (*tpp);
  1498.         *tpp = t;
  1499.         return 0;
  1500.  
  1501.     case tqProc:
  1502.         t = lookup_function_type (*tpp);
  1503.         *tpp = t;
  1504.         return 0;
  1505.  
  1506.     case tqArray:
  1507.         off = 0;
  1508.         t = init_type(TYPE_CODE_ARRAY, 0, 0, 0, (struct objfile *) NULL);
  1509.         TYPE_TARGET_TYPE(t) = *tpp;
  1510.  
  1511.         /* Determine and record the domain type (type of index) */
  1512.         ecoff_swap_rndx_in (bigend, ax, &rndx);
  1513.         id = rndx.index;
  1514.         rf = rndx.rfd;
  1515.         if (rf == 0xfff) {
  1516.             ax++;
  1517.             rf = AUX_GET_ISYM (bigend, ax);
  1518.             off++;
  1519.         }
  1520.         fh = get_rfd(cur_fd, rf);
  1521.  
  1522.         /* Fields are kept in an array */
  1523.         /* FIXME - Memory leak! */
  1524.         if (TYPE_NFIELDS(t))
  1525.             TYPE_FIELDS(t) = (struct field*)
  1526.             xrealloc((PTR) TYPE_FIELDS(t),
  1527.                  (TYPE_NFIELDS(t)+1) * sizeof(struct field));
  1528.         else
  1529.             TYPE_FIELDS(t) = (struct field*)
  1530.             xzalloc(sizeof(struct field));
  1531.         f = &(TYPE_FIELD(t,TYPE_NFIELDS(t)));
  1532.         TYPE_NFIELDS(t)++;
  1533.         memset((PTR)f, 0, sizeof(struct field));
  1534.  
  1535. /* XXX */    f->type = parse_type(id + (union aux_ext *)fh->iauxBase,
  1536.                      &f->bitsize, bigend);
  1537.  
  1538.         ax++;
  1539.         lower = AUX_GET_DNLOW (bigend, ax);
  1540.         ax++;
  1541.         upper = AUX_GET_DNHIGH (bigend, ax);
  1542.         ax++;
  1543.         rf = AUX_GET_WIDTH (bigend, ax);    /* bit size of array element */
  1544.  
  1545.         /* Check whether supplied array element bit size matches
  1546.            the known size of the element type.  If this complaint
  1547.            ends up not happening, we can remove this code.  It's
  1548.            here because we aren't sure we understand this *&%&$
  1549.            symbol format.  */
  1550.         id = TYPE_LENGTH(TYPE_TARGET_TYPE(t)) << 3; /* bitsize */
  1551.         if (id == 0) {
  1552.             /* Most likely an undefined type */
  1553.             id = rf;
  1554.             TYPE_LENGTH(TYPE_TARGET_TYPE(t)) = id >> 3;
  1555.         }
  1556.         if (id != rf)
  1557.             complain (&array_bitsize_complaint, (char *)rf);
  1558.  
  1559.         TYPE_LENGTH(t) = (upper < 0) ? 0 :
  1560.             (upper - lower + 1) * (rf >> 3);
  1561.         *tpp = t;
  1562.         return 4 + off;
  1563.  
  1564.     case tqVol:
  1565.         /* Volatile -- currently ignored */
  1566.         return 0;
  1567.  
  1568.     default:
  1569.         complain (&unknown_type_qual_complaint, (char *)tq);
  1570.         return 0;
  1571.     }
  1572. }
  1573.  
  1574.  
  1575. /* Parse a procedure descriptor record PR.  Note that the procedure
  1576.    is parsed _after_ the local symbols, now we just make up the
  1577.    extra information we need into a special symbol that we insert
  1578.    in the procedure's main block.  Note also that images that
  1579.    have been partially stripped (ld -x) have been deprived
  1580.    of local symbols, and we have to cope with them here.
  1581.    The procedure's code ends at BOUND */
  1582.  
  1583. static void
  1584. parse_procedure(pr, bound, have_stabs)
  1585.     PDR *pr;
  1586.     int bound;
  1587.     int have_stabs;
  1588. {
  1589.     struct symbol *s, *i;
  1590.     SYMR *sh = (SYMR*)pr->isym;
  1591.     struct block *b;
  1592.     struct mips_extra_func_info *e;
  1593.     char name[100];
  1594.     char *sh_name;
  1595.  
  1596.     /* Make up a name for static procedures. Sigh. */
  1597.     if (sh == (SYMR*)-1) {
  1598.         sprintf(name,".static_procedure@%x",pr->adr);
  1599.         sh_name = savestring(name, strlen(name));
  1600.         s = NULL;
  1601.     }
  1602.     else {
  1603.         sh_name = (char*)sh->iss;
  1604.         if (have_stabs)
  1605.         s = lookup_symbol(sh_name, NULL, VAR_NAMESPACE, 0, NULL);
  1606.         else
  1607.         s = mylookup_symbol(sh_name, top_stack->cur_block,
  1608.                     VAR_NAMESPACE, LOC_BLOCK);
  1609.     }
  1610.     if (s != 0) {
  1611.         b = SYMBOL_BLOCK_VALUE(s);
  1612.     } else {
  1613.         s = new_symbol(sh_name);
  1614.         SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
  1615.         SYMBOL_CLASS(s) = LOC_BLOCK;
  1616.         /* Donno its type, hope int is ok */
  1617.         SYMBOL_TYPE(s) = lookup_function_type (builtin_type_int);
  1618.         add_symbol(s, top_stack->cur_block);
  1619.         /* Wont have symbols for this one */
  1620.         b = new_block(2);
  1621.         SYMBOL_BLOCK_VALUE(s) = b;
  1622.         BLOCK_FUNCTION(b) = s;
  1623.         BLOCK_START(b) = pr->adr;
  1624.         BLOCK_END(b) = bound;
  1625.         BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
  1626.         add_block(b, top_stack->cur_st);
  1627.     }
  1628.  
  1629.     i = mylookup_symbol(".gdbinfo.", b, LABEL_NAMESPACE, LOC_CONST);
  1630.  
  1631.     if (i)
  1632.       {
  1633.         e = (struct mips_extra_func_info *)SYMBOL_VALUE(i);
  1634.         e->pdr = *pr;
  1635.         e->pdr.isym = (long)s;
  1636.       }
  1637. }
  1638.  
  1639. /* Parse the external symbol ES. Just call parse_symbol() after
  1640.    making sure we know where the aux are for it. For procedures,
  1641.    parsing of the PDRs has already provided all the needed
  1642.    information, we only parse them if SKIP_PROCEDURES is false,
  1643.    and only if this causes no symbol duplication.
  1644.    BIGEND says whether aux entries are big-endian or little-endian.
  1645.  
  1646.    This routine clobbers top_stack->cur_block and ->cur_st. */
  1647.  
  1648. static void
  1649. parse_external(es, skip_procedures, bigend)
  1650.     EXTR *es;
  1651.     int skip_procedures;
  1652.     int bigend;
  1653. {
  1654.     union aux_ext *ax;
  1655.  
  1656.     if (es->ifd != ifdNil) {
  1657.         cur_fd = es->ifd;
  1658.         cur_fdr = (FDR*)(cur_hdr->cbFdOffset) + cur_fd;
  1659.         ax = (union aux_ext *)cur_fdr->iauxBase;
  1660.     } else {
  1661.         cur_fdr = (FDR*)(cur_hdr->cbFdOffset);
  1662.         ax = 0;
  1663.     }
  1664.     top_stack->cur_st = cur_stab;
  1665.     top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
  1666.                          GLOBAL_BLOCK);
  1667.  
  1668.     /* Reading .o files */
  1669.     if (es->asym.sc == scUndefined || es->asym.sc == scNil) {
  1670.         char *what;
  1671.         switch (es->asym.st) {
  1672.         case stStaticProc:
  1673.         case stProc:    what = "procedure"; n_undef_procs++;  break;
  1674.         case stGlobal:    what = "variable";  n_undef_vars++;   break;
  1675.         case stLabel:    what = "label";     n_undef_labels++; break;
  1676.         default :    what = "symbol";                      break;
  1677.         }
  1678.         n_undef_symbols++;
  1679.         if (info_verbose)
  1680.             printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what,
  1681.                 es->asym.iss, fdr_name((char *)cur_fdr->rss));
  1682.         return;
  1683.     }
  1684.  
  1685.     switch (es->asym.st) {
  1686.     case stProc:
  1687.         /* If we have full symbols we do not need more */
  1688.         if (skip_procedures)
  1689.             return;
  1690.         if (mylookup_symbol ((char *)es->asym.iss, top_stack->cur_block,
  1691.                      VAR_NAMESPACE, LOC_BLOCK))
  1692.             break;
  1693.         /* fall through */
  1694.     case stGlobal:
  1695.     case stLabel:
  1696.         /*
  1697.          * Note that the case of a symbol with indexNil
  1698.          * must be handled anyways by parse_symbol().
  1699.          */
  1700.         parse_symbol(&es->asym, ax, bigend);
  1701.         break;
  1702.     default:
  1703.         break;
  1704.     }
  1705. }
  1706.  
  1707. /* Parse the line number info for file descriptor FH into
  1708.    GDB's linetable LT.  MIPS' encoding requires a little bit
  1709.    of magic to get things out.  Note also that MIPS' line
  1710.    numbers can go back and forth, apparently we can live
  1711.    with that and do not need to reorder our linetables */
  1712.  
  1713. static void
  1714. parse_lines(fh, lt)
  1715.     FDR *fh;
  1716.     struct linetable *lt;
  1717. {
  1718.     unsigned char *base = (unsigned char*)fh->cbLineOffset;
  1719.     int j, k;
  1720.     int delta, count, lineno = 0;
  1721.     PDR *pr;
  1722.  
  1723.     if (base == 0)
  1724.         return;
  1725.  
  1726.     /* Scan by procedure descriptors */
  1727.     j = 0, k = 0;
  1728.     for (pr = (PDR*)IPDFIRST(cur_hdr,fh); j < fh->cpd; j++, pr++) {
  1729.         int l, halt;
  1730.  
  1731.         /* No code for this one */
  1732.         if (pr->iline == ilineNil ||
  1733.             pr->lnLow == -1 || pr->lnHigh == -1)
  1734.             continue;
  1735.         /*
  1736.          *    Aurgh! To know where to stop expanding we
  1737.          *    must look-ahead.
  1738.          */
  1739.         for (l = 1; l < (fh->cpd - j); l++)
  1740.             if (pr[l].iline != -1)
  1741.                 break;
  1742.         if (l == (fh->cpd - j))
  1743.             halt = fh->cline;
  1744.         else
  1745.             halt = pr[l].iline;
  1746.         /*
  1747.          * When procedures are moved around the linenumbers
  1748.          * are attributed to the next procedure up
  1749.          */
  1750.         if (pr->iline >= halt) continue;
  1751.  
  1752.         base = (unsigned char*)pr->cbLineOffset;
  1753.         l = pr->adr >> 2;    /* in words */
  1754.         halt += (pr->adr >> 2) - pr->iline;
  1755.         for (lineno = pr->lnLow; l < halt;) {
  1756.             count = *base & 0x0f;
  1757.             delta = *base++ >> 4;
  1758.             if (delta >= 8)
  1759.                 delta -= 16;
  1760.             if (delta == -8) {
  1761.                 delta = (base[0] << 8) | base[1];
  1762.                 if (delta >= 0x8000)
  1763.                     delta -= 0x10000;
  1764.                 base += 2;
  1765.             }
  1766.             lineno += delta;/* first delta is 0 */
  1767.             k = add_line(lt, lineno, l, k);
  1768.             l += count + 1;
  1769.         }
  1770.     }
  1771. }
  1772.  
  1773.  
  1774. /* Master parsing procedure for first-pass reading of file symbols
  1775.    into a partial_symtab.
  1776.  
  1777.    Parses the symtab described by the global symbolic header CUR_HDR.
  1778.    END_OF_TEXT_SEG gives the address just after the text segment for
  1779.    the symtab we are reading.  */
  1780.  
  1781. static void
  1782. parse_partial_symbols(end_of_text_seg, objfile)
  1783.      int end_of_text_seg;
  1784.      struct objfile *objfile;
  1785. {
  1786.     int             f_idx, s_idx;
  1787. /*    int  stat_idx, h_max;*/
  1788.     HDRR        *hdr = cur_hdr;
  1789.     /* Running pointers */
  1790.     FDR        *fh;
  1791.     register EXTR    *esh;
  1792.     register SYMR    *sh;
  1793.     struct partial_symtab *pst;
  1794.     
  1795.     int past_first_source_file = 0;
  1796.     
  1797.     /* List of current psymtab's include files */
  1798.     char **psymtab_include_list;
  1799.     int includes_allocated;
  1800.     int includes_used;
  1801.     EXTR **extern_tab;
  1802.     struct pst_map * fdr_to_pst;
  1803.     /* Index within current psymtab dependency list */
  1804.     struct partial_symtab **dependency_list;
  1805.     int dependencies_used, dependencies_allocated;
  1806.     struct cleanup *old_chain;
  1807.     
  1808.     extern_tab = (EXTR**)obstack_alloc (&objfile->psymbol_obstack,
  1809.                     sizeof(EXTR *) * hdr->iextMax);
  1810.    
  1811.     includes_allocated = 30;
  1812.     includes_used = 0;
  1813.     psymtab_include_list = (char **) alloca (includes_allocated *
  1814.                          sizeof (char *));
  1815.     next_symbol_text_func = mips_next_symbol_text;
  1816.     
  1817.     dependencies_allocated = 30;
  1818.     dependencies_used = 0;
  1819.     dependency_list =
  1820.     (struct partial_symtab **) alloca (dependencies_allocated *
  1821.                        sizeof (struct partial_symtab *));
  1822.     
  1823.     last_source_file = 0;
  1824.  
  1825.     /*
  1826.      * Big plan: 
  1827.      *
  1828.      * Only parse the Local and External symbols, and the Relative FDR.
  1829.      * Fixup enough of the loader symtab to be able to use it.
  1830.      * Allocate space only for the file's portions we need to
  1831.      * look at. (XXX)
  1832.      */
  1833.     
  1834.     max_gdbinfo = 0;
  1835.     max_glevel = MIN_GLEVEL;
  1836.     
  1837.     /* Allocate the map FDR -> PST.
  1838.        Minor hack: -O3 images might claim some global data belongs
  1839.        to FDR -1. We`ll go along with that */
  1840.     fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst);
  1841.     old_chain = make_cleanup (free, fdr_to_pst);
  1842.     fdr_to_pst++;
  1843.     {
  1844.     struct partial_symtab * pst = new_psymtab("", objfile);
  1845.     fdr_to_pst[-1].pst = pst;
  1846.     FDR_IDX(pst) = -1;
  1847.     }
  1848.     
  1849.     /* Pass 1 over external syms: Presize and partition the list */
  1850.     for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
  1851.     esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
  1852.     fdr_to_pst[esh->ifd].n_globals++;
  1853.     }
  1854.     
  1855.     /* Pass 1.5 over files:  partition out global symbol space */
  1856.     s_idx = 0;
  1857.     for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) {
  1858.     fdr_to_pst[f_idx].globals_offset = s_idx;
  1859.     s_idx += fdr_to_pst[f_idx].n_globals;
  1860.     fdr_to_pst[f_idx].n_globals = 0;
  1861.     }
  1862.  
  1863. /* Pass 2 over external syms: fill in external symbols */
  1864.     for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
  1865.         enum minimal_symbol_type ms_type = mst_text;
  1866.         esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
  1867.  
  1868.         extern_tab[fdr_to_pst[esh->ifd].globals_offset
  1869.                + fdr_to_pst[esh->ifd].n_globals++] = esh;
  1870.  
  1871.         if (esh->asym.sc == scUndefined || esh->asym.sc == scNil)
  1872.             continue;
  1873.  
  1874.         switch (esh->asym.st) {
  1875.         case stProc:
  1876.             break;
  1877.         case stGlobal:
  1878.             ms_type = mst_data;
  1879.             break;
  1880.         case stLabel:
  1881.             break;
  1882.         default:
  1883.             ms_type = mst_unknown;
  1884.             complain (&unknown_ext_complaint,
  1885.                   (char *)(esh->asym.iss));
  1886.         }
  1887.         prim_record_minimal_symbol ((char *)esh->asym.iss,
  1888.                         esh->asym.value,
  1889.                         ms_type);
  1890.     }
  1891.  
  1892.     /* Pass 3 over files, over local syms: fill in static symbols */
  1893.     for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
  1894.         struct partial_symtab *save_pst;
  1895.         EXTR **ext_ptr;
  1896.         cur_fdr = fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
  1897.  
  1898.         if (fh->csym == 0) {
  1899.         fdr_to_pst[f_idx].pst = NULL;
  1900.         continue;
  1901.         }
  1902.         pst = start_psymtab_common (objfile, 0, (char*)fh->rss,
  1903.                     fh->cpd ? fh->adr : 0,
  1904.                     objfile->global_psymbols.next,
  1905.                     objfile->static_psymbols.next);
  1906.         pst->read_symtab_private = (char *)
  1907.         obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
  1908.  
  1909.         save_pst = pst;
  1910.         /* Make everything point to everything. */
  1911.         FDR_IDX(pst) = f_idx;
  1912.         fdr_to_pst[f_idx].pst = pst;
  1913.         fh->ioptBase = (int)pst;
  1914.         
  1915.         CUR_HDR(pst) = cur_hdr;
  1916.         
  1917.         /* The way to turn this into a symtab is to call... */
  1918.         pst->read_symtab = mipscoff_psymtab_to_symtab;
  1919.         
  1920.         pst->texthigh = pst->textlow;
  1921.         
  1922. #if 0        /* This is done in start_psymtab_common */
  1923.         pst->globals_offset = global_psymbols.next - global_psymbols.list;
  1924.         pst->statics_offset = static_psymbols.next - static_psymbols.list;
  1925.         
  1926.         pst->n_global_syms = 0;
  1927.         pst->n_static_syms = 0;
  1928. #endif
  1929.         
  1930.         /* The second symbol must be @stab.
  1931.            This symbol is emitted by mips-tfile to signal
  1932.            that the current object file uses encapsulated stabs
  1933.            instead of mips ecoff for local symbols.
  1934.            (It is the second symbol because the first symbol is
  1935.            the stFile used to signal the start of a file). */
  1936.         if (fh->csym >= 2
  1937.         && strcmp((char *)(((SYMR *)fh->isymBase)[1].iss),
  1938.               stabs_symbol) == 0) {
  1939.         for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) {
  1940.             int type_code;
  1941.             char *namestring;
  1942.             sh = cur_sdx + (SYMR *) fh->isymBase;
  1943.             type_code = MIPS_UNMARK_STAB(sh->index);
  1944.             if (!MIPS_IS_STAB(sh)) {
  1945.             if (sh->st == stProc || sh->st == stStaticProc) {
  1946.                 long procaddr = sh->value;
  1947.                 sh = AUX_GET_ISYM (fh->fBigendian,
  1948.                    sh->index + (union aux_ext *)(fh->iauxBase))
  1949.                 + (SYMR *) fh->isymBase - 1;
  1950.                 if (sh->st == stEnd) {
  1951.                 long high = procaddr + sh->value;
  1952.                 if (high > pst->texthigh)
  1953.                     pst->texthigh = high;
  1954.                 }
  1955.             }
  1956.             continue;
  1957.             }
  1958. #define SET_NAMESTRING() namestring = (char*)sh->iss
  1959. #define CUR_SYMBOL_TYPE type_code
  1960. #define CUR_SYMBOL_VALUE sh->value
  1961. #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
  1962.   pst = save_pst
  1963. #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
  1964. #define addr 0        /* FIXME, should be offset of addresses */
  1965. #define HANDLE_RBRAC(val) \
  1966.   if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
  1967. #include "partial-stab.h"
  1968. #undef addr
  1969.         }
  1970.         }
  1971.         else {
  1972.         register struct partial_symbol *psym;
  1973.         for (cur_sdx = 0; cur_sdx < fh->csym; ) {
  1974.             char *name;
  1975.             enum address_class class;
  1976.             sh = cur_sdx + (SYMR *) fh->isymBase;
  1977.             
  1978.             if (MIPS_IS_STAB(sh)) {
  1979.             cur_sdx++;
  1980.             continue;
  1981.             }
  1982.  
  1983.             if (sh->sc == scUndefined || sh->sc == scNil ||
  1984.             sh->index == 0xfffff) {
  1985.             /* FIXME, premature? */
  1986.             cur_sdx++;
  1987.             continue;
  1988.             }
  1989.             
  1990.             name = (char *)(sh->iss);
  1991.             
  1992.             switch (sh->st) {
  1993.             long high;
  1994.             long procaddr;
  1995.               case stProc:        /* Asm labels apparently */
  1996.               case stStaticProc:        /* Function */
  1997.             ADD_PSYMBOL_TO_LIST(name, strlen(name),
  1998.                         VAR_NAMESPACE, LOC_BLOCK,
  1999.                         objfile->static_psymbols, sh->value);
  2000.             /* Skip over procedure to next one. */
  2001.             cur_sdx = AUX_GET_ISYM (fh->fBigendian,
  2002.                   sh->index + (union aux_ext *)fh->iauxBase);
  2003.             procaddr = sh->value;
  2004.             
  2005.             sh = cur_sdx + (SYMR *) fh->isymBase - 1;
  2006.             if (sh->st != stEnd)
  2007.                 continue;
  2008.             high = procaddr + sh->value;
  2009.             if (high > pst->texthigh)
  2010.                 pst->texthigh = high;
  2011.             continue;
  2012.               case stStatic:            /* Variable */
  2013.             class = LOC_STATIC;
  2014.             break;
  2015.               case stTypedef:            /* Typedef */
  2016.             class = LOC_TYPEDEF;
  2017.             break;
  2018.               case stConstant:        /* Constant decl */
  2019.             class = LOC_CONST;
  2020.             break;
  2021.               case stUnion:
  2022.               case stStruct:
  2023.               case stEnum:
  2024.               case stBlock:            /* { }, str, un, enum*/
  2025.             if (sh->sc == scInfo) {
  2026.                 ADD_PSYMBOL_TO_LIST(name, strlen(name),
  2027.                         STRUCT_NAMESPACE, LOC_TYPEDEF,
  2028.                         objfile->static_psymbols, sh->value);
  2029.             }
  2030.             /* Skip over the block */
  2031.             cur_sdx = sh->index;
  2032.             continue;
  2033.               case stFile:            /* File headers */
  2034.               case stLabel:            /* Labels */
  2035.               case stEnd:            /* Ends of files */
  2036.             goto skip;
  2037.               default:
  2038.             /* Both complaints are valid:  one gives symbol name,
  2039.                the other the offending symbol type.  */
  2040.             complain (&unknown_sym_complaint, (char *)sh->iss);
  2041.             complain (&unknown_st_complaint, (char *)sh->st);
  2042.             cur_sdx++;
  2043.             continue;
  2044.             }
  2045.             /* Use this gdb symbol */
  2046.             ADD_PSYMBOL_TO_LIST(name, strlen(name),
  2047.                     VAR_NAMESPACE, class,
  2048.                     objfile->static_psymbols, sh->value);
  2049.           skip:
  2050.             cur_sdx++;        /* Go to next file symbol */
  2051.         }
  2052.  
  2053.         /* Now do enter the external symbols. */
  2054.         ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
  2055.         cur_sdx = fdr_to_pst[f_idx].n_globals;
  2056.         PST_PRIVATE(save_pst)->extern_count = cur_sdx;
  2057.         PST_PRIVATE(save_pst)->extern_tab = ext_ptr;
  2058.         for (; --cur_sdx >= 0; ext_ptr++) {
  2059.             enum address_class class;
  2060.             if ((*ext_ptr)->ifd != f_idx)
  2061.             abort();
  2062.             sh = &(*ext_ptr)->asym;
  2063.             switch (sh->st) {
  2064.               case stProc:
  2065.             class = LOC_BLOCK;
  2066.             break;
  2067.               case stLabel:
  2068.             class = LOC_LABEL;
  2069.             break;
  2070.               default:
  2071.             complain (&unknown_ext_complaint, (char *)sh->iss);
  2072.               case stGlobal:
  2073.             class = LOC_STATIC;
  2074.             break;
  2075.             }
  2076.             if (objfile->global_psymbols.next >=
  2077.             objfile->global_psymbols.list + objfile->global_psymbols.size)
  2078.             extend_psymbol_list (&objfile->global_psymbols, objfile);
  2079.             psym = objfile->global_psymbols.next++;
  2080.             SYMBOL_NAME (psym) = (char*)sh->iss;
  2081.             SYMBOL_NAMESPACE (psym) = VAR_NAMESPACE;
  2082.             SYMBOL_CLASS (psym) = class;
  2083.             SYMBOL_VALUE_ADDRESS (psym) = (CORE_ADDR)sh->value;
  2084.         }
  2085.         }
  2086.  
  2087.         end_psymtab (save_pst, psymtab_include_list, includes_used,
  2088.              -1, save_pst->texthigh,
  2089.              dependency_list, dependencies_used);
  2090.         if (objfile -> ei.entry_point >= save_pst->textlow &&
  2091.         objfile -> ei.entry_point <  save_pst->texthigh)
  2092.           {
  2093.         objfile -> ei.entry_file_lowpc = save_pst->textlow;
  2094.         objfile -> ei.entry_file_highpc = save_pst->texthigh;
  2095.           }
  2096.     }
  2097.  
  2098.         /* Mark the last code address, and remember it for later */
  2099.     hdr->cbDnOffset = end_of_text_seg;
  2100.  
  2101.     /* Now scan the FDRs for dependencies */
  2102.     for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
  2103.     int s_id0 = 0;
  2104.     fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
  2105.     pst = fdr_to_pst[f_idx].pst;
  2106.  
  2107.     /* This should catch stabs-in-ecoff. */
  2108.     if (fh->crfd <= 1)
  2109.         continue;
  2110.  
  2111.     if (fh->cpd == 0) {  /* If there are no functions defined here ... */
  2112.         /* ...then presumably a .h file: drop reverse depends .h->.c */
  2113.         for (; s_id0 < fh->crfd; s_id0++) {
  2114.             RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;
  2115.             if (*rh == f_idx) {
  2116.                 s_id0++;    /* Skip self-dependency */
  2117.                 break;
  2118.             }
  2119.         }
  2120.     }
  2121.     pst->number_of_dependencies = fh->crfd - s_id0;
  2122.     pst->dependencies = (struct partial_symtab **)
  2123.         obstack_alloc (&objfile->psymbol_obstack,
  2124.                    pst->number_of_dependencies *
  2125.                    sizeof (struct partial_symtab *));
  2126.     for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {
  2127.         RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;
  2128.         if (*rh < 0 || *rh >= hdr->ifdMax)
  2129.         complain(&bad_file_number_complaint, (char *)*rh);
  2130.         else
  2131.         pst->dependencies[s_idx-s_id0] = fdr_to_pst[*rh].pst;
  2132.     }
  2133.     }
  2134.     do_cleanups (old_chain);
  2135. }
  2136.  
  2137.  
  2138. #if 0
  2139. /* Do the initial analisys of the F_IDX-th file descriptor.
  2140.    Allocates a partial symtab for it, and builds the list
  2141.    of dependent files by recursion. LEV says at which level
  2142.    of recursion we are called (to pretty up debug traces) */
  2143.  
  2144. static struct partial_symtab *
  2145. parse_fdr(f_idx, lev, objfile)
  2146.     int f_idx;
  2147.     int lev;
  2148.     struct objfile *objfile;
  2149. {
  2150.     register FDR *fh;
  2151.     register struct partial_symtab *pst;
  2152.     int s_idx, s_id0;
  2153.  
  2154.     fh = (FDR *) (cur_hdr->cbFdOffset) + f_idx;
  2155.  
  2156.     /* Use this to indicate into which symtab this file was parsed */
  2157.     if (fh->ioptBase)
  2158.         return (struct partial_symtab *) fh->ioptBase;
  2159.  
  2160.     /* Debuggability level */
  2161.     if (compare_glevel(max_glevel, fh->glevel) < 0)
  2162.         max_glevel = fh->glevel;
  2163.  
  2164.     /* Make a new partial_symtab */
  2165.     pst = new_psymtab(fh->rss, objfile);
  2166.     if (fh->cpd == 0){
  2167.         pst->textlow = 0;
  2168.         pst->texthigh = 0;
  2169.     } else {
  2170.         pst->textlow = fh->adr;
  2171.         pst->texthigh = fh->cpd;    /* To be fixed later */
  2172.     }
  2173.  
  2174.     /* Make everything point to everything. */
  2175.     FDR_IDX(pst) = f_idx;
  2176.     fdr_to_pst[f_idx].pst = pst;
  2177.     fh->ioptBase = (int)pst;
  2178.  
  2179.     /* Analyze its dependencies */
  2180.     if (fh->crfd <= 1)
  2181.         return pst;
  2182.  
  2183.     s_id0 = 0;
  2184.     if (fh->cpd == 0) {  /* If there are no functions defined here ... */
  2185.         /* ...then presumably a .h file: drop reverse depends .h->.c */
  2186.         for (; s_id0 < fh->crfd; s_id0++) {
  2187.             RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;
  2188.             if (*rh == f_idx) {
  2189.                 s_id0++;    /* Skip self-dependency */
  2190.                 break;
  2191.             }
  2192.         }
  2193.     }
  2194.     pst->number_of_dependencies = fh->crfd - s_id0;
  2195.     pst->dependencies = (struct partial_symtab **)
  2196.         obstack_alloc (&objfile->psymbol_obstack,
  2197.                  pst->number_of_dependencies *
  2198.                    sizeof (struct partial_symtab *));
  2199.     for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {
  2200.         RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;
  2201.  
  2202.         pst->dependencies[s_idx-s_id0] = parse_fdr(*rh, lev+1, objfile);
  2203.     }
  2204.  
  2205.     return pst;
  2206. }
  2207. #endif
  2208.  
  2209. static char*
  2210. mips_next_symbol_text ()
  2211. {
  2212.     cur_sdx++;
  2213.     return (char*)((SYMR *)cur_fdr->isymBase)[cur_sdx].iss;
  2214. }
  2215.  
  2216. /* Ancillary function to psymtab_to_symtab().  Does all the work
  2217.    for turning the partial symtab PST into a symtab, recurring
  2218.    first on all dependent psymtabs.  The argument FILENAME is
  2219.    only passed so we can see in debug stack traces what file
  2220.    is being read. */
  2221.  
  2222. static void
  2223. psymtab_to_symtab_1(pst, filename)
  2224.      struct partial_symtab *pst;
  2225.      char *filename;
  2226. {
  2227.     int have_stabs;
  2228.     int i, f_max;
  2229.     struct symtab  *st;
  2230.     FDR *fh;
  2231.     int maxlines;
  2232.     struct linetable *lines;
  2233.  
  2234.     if (pst->readin)
  2235.     return;
  2236.     pst->readin = 1;
  2237.     
  2238.     /* How many symbols will we need */
  2239.     /* FIXME, this does not count enum values. */
  2240.     f_max = pst->n_global_syms + pst->n_static_syms;
  2241.     if (FDR_IDX(pst) == -1) {
  2242.     fh = 0;
  2243.     maxlines = 0;
  2244.     } else {
  2245.     fh = (FDR *) (cur_hdr->cbFdOffset) + FDR_IDX(pst);
  2246.     f_max += fh->csym + fh->cpd;
  2247.     maxlines = 2 * fh->cline;
  2248.     }
  2249.  
  2250.     /* See comment in parse_partial_symbols about the @stabs sentinel. */
  2251.     have_stabs =
  2252.     fh && fh->csym >= 2
  2253.         && strcmp((char *)(((SYMR *)fh->isymBase)[1].iss), stabs_symbol)
  2254.             == 0;
  2255.  
  2256.     if (!have_stabs) {
  2257.     if (fh)
  2258.         st = new_symtab (pst->filename, 2 * f_max, maxlines,
  2259.                  pst->objfile);
  2260.     else
  2261.         st = new_symtab ("unknown", f_max, 0, pst->objfile);
  2262.     lines = LINETABLE(st);
  2263.     pending_list = (struct mips_pending **) cur_hdr->cbOptOffset;
  2264.     if (pending_list == 0) {
  2265.         pending_list = (struct mips_pending **)
  2266.         xzalloc(cur_hdr->ifdMax * sizeof(struct mips_pending *));
  2267.         cur_hdr->cbOptOffset = (int)pending_list;
  2268.     }
  2269.     }
  2270.     
  2271.     /* Read in all partial symbtabs on which this one is dependent.
  2272.        NOTE that we do have circular dependencies, sigh.  We solved
  2273.        that by setting pst->readin before this point.  */
  2274.     
  2275.     for (i = 0; i < pst->number_of_dependencies; i++)
  2276.     if (!pst->dependencies[i]->readin) {
  2277.         /* Inform about additional files to be read in.  */
  2278.         if (info_verbose)
  2279.         {
  2280.             fputs_filtered (" ", stdout);
  2281.             wrap_here ("");
  2282.             fputs_filtered ("and ", stdout);
  2283.             wrap_here ("");
  2284.             printf_filtered ("%s...",
  2285.                      pst->dependencies[i]->filename);
  2286.             wrap_here ("");        /* Flush output */
  2287.             fflush (stdout);
  2288.         }
  2289.         /* We only pass the filename for debug purposes */
  2290.         psymtab_to_symtab_1(pst->dependencies[i], 
  2291.                 pst->dependencies[i]->filename);
  2292.     }
  2293.     
  2294.     cur_fdr = fh;
  2295.     /* Now read the symbols for this symtab */
  2296.     
  2297.     current_objfile = pst -> objfile;
  2298.     if (!have_stabs) {
  2299.     cur_fd = FDR_IDX(pst);
  2300.     cur_stab = st;
  2301.     
  2302.     /* Get a new lexical context */
  2303.     
  2304.     push_parse_stack();
  2305.     top_stack->cur_st = cur_stab;
  2306.     top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab),
  2307.                          STATIC_BLOCK);
  2308.     BLOCK_START(top_stack->cur_block) = fh ? fh->adr : 0;
  2309.     BLOCK_END(top_stack->cur_block) = 0;
  2310.     top_stack->blocktype = stFile;
  2311.     top_stack->maxsyms = 2*f_max;
  2312.     top_stack->cur_type = 0;
  2313.     top_stack->procadr = 0;
  2314.     top_stack->numargs = 0;
  2315.     }
  2316.     
  2317.     /* Parse locals and procedures */
  2318.     if (fh) {
  2319.     SYMR *sh;
  2320.     PDR *pr;
  2321.     
  2322.     /* BOUND is the highest core address of this file's procedures */
  2323.     int bound =  cur_fd == cur_hdr->ifdMax - 1 ? cur_hdr->cbDnOffset
  2324.         : fh[1].adr;
  2325.  
  2326.     /* Parse local symbols first */
  2327.     
  2328.     if (have_stabs) {
  2329.         if (fh->csym <= 2)
  2330.           {
  2331.         current_objfile = NULL;
  2332.         return;
  2333.           }
  2334.         for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) {
  2335.         register SYMR    *sh = cur_sdx + (SYMR *) fh->isymBase;
  2336.         char *name = (char*)sh->iss;
  2337.         CORE_ADDR valu = sh->value;
  2338.         if (MIPS_IS_STAB(sh)) {
  2339.             int type_code = MIPS_UNMARK_STAB(sh->index);
  2340.             process_one_symbol (type_code, 0, valu, name, /*FIXME*/ 0,
  2341.                     pst->objfile);
  2342.             if (type_code == N_FUN) {
  2343.             /* Make up special symbol to contain
  2344.                procedure specific info */
  2345.             struct mips_extra_func_info *e =
  2346.               (struct mips_extra_func_info *)
  2347.                 obstack_alloc(¤t_objfile->symbol_obstack,
  2348.                       sizeof(struct mips_extra_func_info));
  2349.             struct symbol *s = new_symbol(".gdbinfo.");
  2350.             SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
  2351.             SYMBOL_CLASS(s) = LOC_CONST;
  2352.             SYMBOL_TYPE(s) = builtin_type_void;
  2353.             SYMBOL_VALUE(s) = (int)e;
  2354.             add_symbol_to_list (s, &local_symbols);
  2355.             }
  2356.         }
  2357.         else if (sh->st == stLabel && sh->index != indexNil) {
  2358.             /* Handle encoded stab line number. */
  2359.             record_line (current_subfile, sh->index, valu);
  2360.         }
  2361.         }
  2362.         st = end_symtab (pst->texthigh, 0, 0, pst->objfile);
  2363.     }
  2364.     else {
  2365.         for (cur_sdx = 0; cur_sdx < fh->csym; ) {
  2366.         sh = (SYMR *) (fh->isymBase) + cur_sdx;
  2367.         cur_sdx += parse_symbol(sh, (union aux_ent *)fh->iauxBase,
  2368.                     fh->fBigendian);
  2369.         }
  2370.  
  2371.         /* Linenumbers. At the end, check if we can save memory */
  2372.         parse_lines(fh, lines);
  2373.         if (lines->nitems < fh->cline)
  2374.         lines = shrink_linetable(lines);
  2375.     }
  2376.  
  2377.     /* Procedures next, note we need to look-ahead to
  2378.        find out where the procedure's code ends */
  2379.  
  2380.     for (i = 0; i <= fh->cpd-1; i++) {
  2381.         pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + i;
  2382.         parse_procedure(pr,
  2383.                 i < fh->cpd-1 ? pr[1].adr : bound,
  2384.                 have_stabs);
  2385.     }
  2386.     }
  2387.     if (!have_stabs) {
  2388.     EXTR **ext_ptr;
  2389.     LINETABLE(st) = lines;
  2390.     
  2391.     /* .. and our share of externals.
  2392.        XXX use the global list to speed up things here. how ? 
  2393.        FIXME, Maybe quit once we have found the right number of ext's? */
  2394.     /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
  2395.     top_stack->blocktype = stFile;
  2396.     top_stack->maxsyms =
  2397.         cur_hdr->isymMax + cur_hdr->ipdMax + cur_hdr->iextMax;
  2398.  
  2399.     ext_ptr = PST_PRIVATE(pst)->extern_tab;
  2400.     for (i = PST_PRIVATE(pst)->extern_count; --i >= 0; ext_ptr++)
  2401.         parse_external(*ext_ptr, 1, fh->fBigendian);
  2402.     
  2403.     /* If there are undefined, tell the user */
  2404.     if (n_undef_symbols) {
  2405.         printf_filtered("File %s contains %d unresolved references:",
  2406.                 st->filename, n_undef_symbols);
  2407.         printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
  2408.                 n_undef_vars, n_undef_procs, n_undef_labels);
  2409.         n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
  2410.  
  2411.     }
  2412.     pop_parse_stack();
  2413.     }
  2414.     
  2415.     /* Sort the symbol table now, we are done adding symbols to it.*/
  2416.     sort_symtab_syms(st);
  2417.  
  2418.     sort_blocks (st);
  2419.     
  2420.     /* Now link the psymtab and the symtab.  */
  2421.     pst->symtab = st;
  2422.  
  2423.     current_objfile = NULL;
  2424. }
  2425.  
  2426. /* Ancillary parsing procedures. */
  2427.  
  2428. /* Lookup the type at relative index RN.  Return it in TPP
  2429.    if found and in any event come up with its name PNAME.
  2430.    BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
  2431.    Return value says how many aux symbols we ate. */
  2432.  
  2433. static int
  2434. cross_ref(ax, tpp, type_code, pname, bigend)
  2435.      union aux_ext *ax;
  2436.      struct type **tpp;
  2437.      enum type_code type_code; /* Use to alloc new type if none is found. */
  2438.      char **pname;
  2439.      int bigend;
  2440. {
  2441.     RNDXR        rn[1];
  2442.     unsigned        rf;
  2443.     int        result = 1;
  2444.  
  2445.     ecoff_swap_rndx_in (bigend, ax, rn);
  2446.  
  2447.     /* Escape index means 'the next one' */
  2448.     if (rn->rfd == 0xfff) {
  2449.         result++;
  2450.         rf = AUX_GET_ISYM (bigend, ax + 1);
  2451.     } else {
  2452.         rf = rn->rfd;
  2453.     }
  2454.  
  2455.     if (rf == -1) {
  2456.         /* Ooops */
  2457.         *pname = "<undefined>";
  2458.     } else {
  2459.         /*
  2460.          * Find the relative file descriptor and the symbol in it 
  2461.          */
  2462.         FDR            *fh = get_rfd(cur_fd, rf);
  2463.         SYMR           *sh;
  2464.         struct type    *t;
  2465.  
  2466.         /*
  2467.          * If we have processed this symbol then we left a forwarding
  2468.          * pointer to the corresponding GDB symbol.  If not, we`ll put
  2469.          * it in a list of pending symbols, to be processed later when
  2470.          * the file f will be.  In any event, we collect the name for
  2471.          * the type here. Which is why we made a first pass at
  2472.          * strings. 
  2473.          */
  2474.         sh = (SYMR *) (fh->isymBase) + rn->index;
  2475.  
  2476.         /* Careful, we might be looking at .o files */
  2477.         *pname = (UNSAFE_DATA_ADDR(sh->iss)) ? "<undefined>" :
  2478.             (char *) sh->iss;
  2479.  
  2480.         /* Have we parsed it ? */
  2481.         if ((!UNSAFE_DATA_ADDR(sh->value)) && (sh->st == stParsed)) {
  2482.             t = (struct type *) sh->value;
  2483.             *tpp = t;
  2484.         } else {
  2485.             /* Avoid duplicates */
  2486.             struct mips_pending *p = is_pending_symbol(fh, sh);
  2487.             if (p)
  2488.             *tpp = p->t;
  2489.             else {
  2490.             *tpp = init_type(type_code, 0, 0, 0, (struct objfile *) NULL);
  2491.             add_pending(fh, sh, *tpp);
  2492.             }
  2493.         }
  2494.     }
  2495.  
  2496.     /* We used one auxent normally, two if we got a "next one" rf. */
  2497.     return result;
  2498. }
  2499.  
  2500.  
  2501. /* Quick&dirty lookup procedure, to avoid the MI ones that require
  2502.    keeping the symtab sorted */
  2503.  
  2504. static struct symbol *
  2505. mylookup_symbol (name, block, namespace, class)
  2506.      char *name;
  2507.      register struct block *block;
  2508.      enum namespace namespace;
  2509.      enum address_class class;
  2510. {
  2511.     register int    bot, top, inc;
  2512.     register struct symbol *sym;
  2513.  
  2514.     bot = 0;
  2515.     top = BLOCK_NSYMS(block);
  2516.     inc = name[0];
  2517.     while (bot < top) {
  2518.         sym = BLOCK_SYM(block, bot);
  2519.         if (SYMBOL_NAME(sym)[0] == inc
  2520.             && SYMBOL_NAMESPACE(sym) == namespace
  2521.             && SYMBOL_CLASS(sym) == class
  2522.             && !strcmp(SYMBOL_NAME(sym), name))
  2523.             return sym;
  2524.         bot++;
  2525.     }
  2526.     block = BLOCK_SUPERBLOCK (block);
  2527.     if (block)
  2528.         return mylookup_symbol (name, block, namespace, class);
  2529.     return 0;
  2530. }
  2531.  
  2532.  
  2533. /* Add a new symbol S to a block B.
  2534.    Infrequently, we will need to reallocate the block to make it bigger.
  2535.    We only detect this case when adding to top_stack->cur_block, since
  2536.    that's the only time we know how big the block is.  FIXME.  */
  2537.  
  2538. static void
  2539. add_symbol(s,b)
  2540.     struct symbol *s;
  2541.     struct block *b;
  2542. {
  2543.     int nsyms = BLOCK_NSYMS(b)++;
  2544.     struct block *origb;
  2545.     struct parse_stack *stackp;
  2546.  
  2547.     if (b == top_stack->cur_block &&
  2548.         nsyms >= top_stack->maxsyms) {
  2549.         complain (&block_overflow_complaint, s->name);
  2550.         /* In this case shrink_block is actually grow_block, since
  2551.            BLOCK_NSYMS(b) is larger than its current size.  */
  2552.         origb = b;
  2553.         b = shrink_block (top_stack->cur_block, top_stack->cur_st);
  2554.  
  2555.         /* Now run through the stack replacing pointers to the
  2556.            original block.  shrink_block has already done this
  2557.            for the blockvector and BLOCK_FUNCTION.  */
  2558.         for (stackp = top_stack; stackp; stackp = stackp->next) {
  2559.             if (stackp->cur_block == origb) {
  2560.                 stackp->cur_block = b;
  2561.                 stackp->maxsyms = BLOCK_NSYMS (b);
  2562.             }
  2563.         }
  2564.     }
  2565.     BLOCK_SYM(b,nsyms) = s;
  2566. }
  2567.  
  2568. /* Add a new block B to a symtab S */
  2569.  
  2570. static void
  2571. add_block(b,s)
  2572.     struct block *b;
  2573.     struct symtab *s;
  2574. {
  2575.     struct blockvector *bv = BLOCKVECTOR(s);
  2576.  
  2577.     bv = (struct blockvector *)xrealloc((PTR) bv,
  2578.                         sizeof(struct blockvector) +
  2579.                              BLOCKVECTOR_NBLOCKS(bv)
  2580.                          * sizeof(bv->block));
  2581.     if (bv != BLOCKVECTOR(s))
  2582.         BLOCKVECTOR(s) = bv;
  2583.  
  2584.     BLOCKVECTOR_BLOCK(bv, BLOCKVECTOR_NBLOCKS(bv)++) = b;
  2585. }
  2586.  
  2587. /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
  2588.    MIPS' linenumber encoding might need more than one byte
  2589.    to describe it, LAST is used to detect these continuation lines */
  2590.  
  2591. static int
  2592. add_line(lt, lineno, adr, last)
  2593.     struct linetable *lt;
  2594.     int lineno;
  2595.     CORE_ADDR adr;
  2596.     int last;
  2597. {
  2598.     if (last == 0)
  2599.         last = -2;    /* make sure we record first line */
  2600.  
  2601.     if (last == lineno)    /* skip continuation lines */
  2602.         return lineno;
  2603.  
  2604.     lt->item[lt->nitems].line = lineno;
  2605.     lt->item[lt->nitems++].pc = adr << 2;
  2606.     return lineno;
  2607. }
  2608.  
  2609. /* Sorting and reordering procedures */
  2610.  
  2611. /* Blocks with a smaller low bound should come first */
  2612.  
  2613. static int
  2614. compare_blocks(arg1, arg2)
  2615.      const void *arg1, *arg2;
  2616. {
  2617.     register int addr_diff;
  2618.     struct block **b1 = (struct block **) arg1;
  2619.     struct block **b2 = (struct block **) arg2;
  2620.  
  2621.     addr_diff = (BLOCK_START((*b1))) - (BLOCK_START((*b2)));
  2622.     if (addr_diff == 0)
  2623.         return (BLOCK_END((*b1))) - (BLOCK_END((*b2)));
  2624.     return addr_diff;
  2625. }
  2626.  
  2627. /* Sort the blocks of a symtab S.
  2628.    Reorder the blocks in the blockvector by code-address,
  2629.    as required by some MI search routines */
  2630.  
  2631. static void
  2632. sort_blocks(s)
  2633.     struct symtab *s;
  2634. {
  2635.     struct blockvector *bv = BLOCKVECTOR(s);
  2636.  
  2637.     if (BLOCKVECTOR_NBLOCKS(bv) <= 2) {
  2638.         /* Cosmetic */
  2639.         if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) == 0)
  2640.             BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = 0;
  2641.         if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) == 0)
  2642.             BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) = 0;
  2643.         return;
  2644.     }
  2645.     /*
  2646.      * This is very unfortunate: normally all functions are compiled in
  2647.      * the order they are found, but if the file is compiled -O3 things
  2648.      * are very different.  It would be nice to find a reliable test
  2649.      * to detect -O3 images in advance.
  2650.      */
  2651.     if (BLOCKVECTOR_NBLOCKS(bv) > 3)
  2652.         qsort(&BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK),
  2653.               BLOCKVECTOR_NBLOCKS(bv) - FIRST_LOCAL_BLOCK,
  2654.               sizeof(struct block *),
  2655.               compare_blocks);
  2656.  
  2657.     {
  2658.         register CORE_ADDR high = 0;
  2659.         register int    i, j = BLOCKVECTOR_NBLOCKS(bv);
  2660.  
  2661.         for (i = FIRST_LOCAL_BLOCK; i < j; i++)
  2662.             if (high < BLOCK_END(BLOCKVECTOR_BLOCK(bv,i)))
  2663.                 high = BLOCK_END(BLOCKVECTOR_BLOCK(bv,i));
  2664.         BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = high;
  2665.     }
  2666.  
  2667.     BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) =
  2668.         BLOCK_START(BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK));
  2669.  
  2670.     BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) = 
  2671.         BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
  2672.     BLOCK_END  (BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
  2673.         BLOCK_END  (BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
  2674. }
  2675.  
  2676.  
  2677. /* Constructor/restructor/destructor procedures */
  2678.  
  2679. /* Allocate a new symtab for NAME.  Needs an estimate of how many symbols
  2680.    MAXSYMS and linenumbers MAXLINES we'll put in it */
  2681.  
  2682. static struct symtab *
  2683. new_symtab(name, maxsyms, maxlines, objfile)
  2684.     char *name;
  2685.     int maxsyms;
  2686.     int maxlines;
  2687.     struct objfile *objfile;
  2688. {
  2689.   struct symtab *s = allocate_symtab (name, objfile);
  2690.  
  2691.   LINETABLE(s) = new_linetable(maxlines);
  2692.  
  2693.   /* All symtabs must have at least two blocks */
  2694.   BLOCKVECTOR(s) = new_bvect(2);
  2695.   BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK) = new_block(maxsyms);
  2696.   BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), STATIC_BLOCK) = new_block(maxsyms);
  2697.   BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s),STATIC_BLOCK)) =
  2698.     BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK);
  2699.  
  2700.   s->free_code = free_linetable;
  2701.  
  2702.   return (s);
  2703. }
  2704.  
  2705. /* Allocate a new partial_symtab NAME */
  2706.  
  2707. static struct partial_symtab *
  2708. new_psymtab(name, objfile)
  2709.     char *name;
  2710.     struct objfile *objfile;
  2711. {
  2712.   struct partial_symtab *psymtab;
  2713.   
  2714.   /* FIXME -- why (char *) -1 rather than NULL? */
  2715.   psymtab = allocate_psymtab (name == (char *) -1 ? "<no name>" : name,
  2716.                   objfile);
  2717.   
  2718.   /* Keep a backpointer to the file's symbols */
  2719.  
  2720.   psymtab -> read_symtab_private = (char *)
  2721.     obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
  2722.   CUR_HDR(psymtab) = cur_hdr;
  2723.   
  2724.   /* The way to turn this into a symtab is to call... */
  2725.   psymtab->read_symtab = mipscoff_psymtab_to_symtab;
  2726.   return (psymtab);
  2727. }
  2728.  
  2729.  
  2730. /* Allocate a linetable array of the given SIZE.  Since the struct
  2731.    already includes one item, we subtract one when calculating the 
  2732.    proper size to allocate.  */
  2733.  
  2734. static struct linetable *
  2735. new_linetable(size)
  2736.     int size;
  2737. {
  2738.     struct linetable *l;
  2739.  
  2740.     size = (size-1) * sizeof(l->item) + sizeof(struct linetable);
  2741.     l = (struct linetable *)xmalloc(size);
  2742.     l->nitems = 0;
  2743.     return l;
  2744. }
  2745.  
  2746. /* Oops, too big. Shrink it.  This was important with the 2.4 linetables,
  2747.    I am not so sure about the 3.4 ones.
  2748.  
  2749.    Since the struct linetable already includes one item, we subtract one when
  2750.    calculating the proper size to allocate.  */
  2751.  
  2752. static struct linetable *
  2753. shrink_linetable(lt)
  2754.     struct linetable * lt;
  2755. {
  2756.  
  2757.     return (struct linetable *) xrealloc ((PTR)lt, 
  2758.                     sizeof(struct linetable)
  2759.                     + (lt->nitems - 1) * sizeof(lt->item));
  2760. }
  2761.  
  2762. /* Allocate and zero a new blockvector of NBLOCKS blocks. */
  2763.  
  2764. static struct blockvector *
  2765. new_bvect(nblocks)
  2766.     int nblocks;
  2767. {
  2768.     struct blockvector *bv;
  2769.     int size;
  2770.  
  2771.     size = sizeof(struct blockvector) + nblocks * sizeof(struct block*);
  2772.     bv = (struct blockvector *) xzalloc(size);
  2773.  
  2774.     BLOCKVECTOR_NBLOCKS(bv) = nblocks;
  2775.  
  2776.     return bv;
  2777. }
  2778.  
  2779. /* Allocate and zero a new block of MAXSYMS symbols */
  2780.  
  2781. static struct block *
  2782. new_block(maxsyms)
  2783.     int maxsyms;
  2784. {
  2785.     int size = sizeof(struct block) + (maxsyms-1) * sizeof(struct symbol *);
  2786.  
  2787.     return (struct block *)xzalloc (size);
  2788. }
  2789.  
  2790. /* Ooops, too big. Shrink block B in symtab S to its minimal size.
  2791.    Shrink_block can also be used by add_symbol to grow a block.  */
  2792.  
  2793. static struct block *
  2794. shrink_block(b, s)
  2795.     struct block *b;
  2796.     struct symtab *s;
  2797. {
  2798.     struct block *new;
  2799.     struct blockvector *bv = BLOCKVECTOR(s);
  2800.     int i;
  2801.  
  2802.     /* Just reallocate it and fix references to the old one */
  2803.  
  2804.     new = (struct block *) xrealloc ((PTR)b, sizeof(struct block) +
  2805.         (BLOCK_NSYMS(b)-1) * sizeof(struct symbol *));
  2806.  
  2807.     /* Should chase pointers to old one.  Fortunately, that`s just
  2808.        the block`s function and inferior blocks */
  2809.     if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b)
  2810.         SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
  2811.     for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++)
  2812.         if (BLOCKVECTOR_BLOCK(bv,i) == b)
  2813.             BLOCKVECTOR_BLOCK(bv,i) = new;
  2814.         else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) == b)
  2815.             BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) = new;
  2816.     return new;
  2817. }
  2818.  
  2819. /* Create a new symbol with printname NAME */
  2820.  
  2821. static struct symbol *
  2822. new_symbol(name)
  2823.     char *name;
  2824. {
  2825.     struct symbol *s = (struct symbol *) 
  2826.         obstack_alloc (¤t_objfile->symbol_obstack, sizeof (struct symbol));
  2827.  
  2828.     memset ((PTR)s, 0, sizeof (*s));
  2829.     SYMBOL_NAME(s) = name;
  2830.     return s;
  2831. }
  2832.  
  2833. /* Create a new type with printname NAME */
  2834.  
  2835. static struct type *
  2836. new_type(name)
  2837.     char *name;
  2838. {
  2839.     struct type *t;
  2840.  
  2841.     t = alloc_type (current_objfile);
  2842.     TYPE_NAME(t) = name;
  2843.     TYPE_CPLUS_SPECIFIC(t) = (struct cplus_struct_type *)
  2844.                  &cplus_struct_default;
  2845.     return t;
  2846. }
  2847.  
  2848.  
  2849. /* Things used for calling functions in the inferior.
  2850.    These functions are exported to our companion
  2851.    mips-tdep.c file and are here because they play
  2852.    with the symbol-table explicitly. */
  2853.  
  2854. /* Sigtramp: make sure we have all the necessary information
  2855.    about the signal trampoline code. Since the official code
  2856.    from MIPS does not do so, we make up that information ourselves.
  2857.    If they fix the library (unlikely) this code will neutralize itself. */
  2858.  
  2859. static void
  2860. fixup_sigtramp()
  2861. {
  2862.     struct symbol  *s;
  2863.     struct symtab  *st;
  2864.     struct block   *b, *b0;
  2865.  
  2866.     sigtramp_address = -1;
  2867.  
  2868.     /* We know it is sold as sigvec */
  2869.     s = lookup_symbol("sigvec", 0, VAR_NAMESPACE, 0, NULL);
  2870.  
  2871.     /* Most programs do not play with signals */
  2872.     if (s == 0)
  2873.       s = lookup_symbol("_sigtramp", 0, VAR_NAMESPACE, 0, NULL);
  2874.     else
  2875.       {
  2876.         b0 = SYMBOL_BLOCK_VALUE(s);
  2877.  
  2878.         /* A label of sigvec, to be more precise */
  2879.         s = lookup_symbol("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
  2880.       }
  2881.  
  2882.     /* But maybe this program uses its own version of sigvec */
  2883.     if (s == 0)
  2884.         return;
  2885.  
  2886.     /* Did we or MIPSco fix the library ? */
  2887.     if (SYMBOL_CLASS(s) == LOC_BLOCK)
  2888.       {
  2889.         sigtramp_address = BLOCK_START(SYMBOL_BLOCK_VALUE(s));
  2890.         sigtramp_end = BLOCK_END(SYMBOL_BLOCK_VALUE(s));
  2891.         return;
  2892.       }
  2893.  
  2894.     sigtramp_address = SYMBOL_VALUE(s);
  2895.     sigtramp_end = sigtramp_address + 0x88;    /* black magic */
  2896.  
  2897.     /* But what symtab does it live in ? */
  2898.     st = find_pc_symtab(SYMBOL_VALUE(s));
  2899.  
  2900.     /*
  2901.      * Ok, there goes the fix: turn it into a procedure, with all the
  2902.      * needed info.  Note we make it a nested procedure of sigvec,
  2903.      * which is the way the (assembly) code is actually written.
  2904.      */
  2905.     SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
  2906.     SYMBOL_CLASS(s) = LOC_BLOCK;
  2907.     SYMBOL_TYPE(s) = init_type(TYPE_CODE_FUNC, 4, 0, 0, (struct objfile *) NULL);
  2908.     TYPE_TARGET_TYPE(SYMBOL_TYPE(s)) = builtin_type_void;
  2909.  
  2910.     /* Need a block to allocate .gdbinfo. in */
  2911.     b = new_block(1);
  2912.     SYMBOL_BLOCK_VALUE(s) = b;
  2913.     BLOCK_START(b) = sigtramp_address;
  2914.     BLOCK_END(b) = sigtramp_end;
  2915.     BLOCK_FUNCTION(b) = s;
  2916.     BLOCK_SUPERBLOCK(b) = BLOCK_SUPERBLOCK(b0);
  2917.     add_block(b, st);
  2918.     sort_blocks(st);
  2919.  
  2920.     /* Make a .gdbinfo. for it */
  2921.     {
  2922.         struct mips_extra_func_info *e =
  2923.             (struct mips_extra_func_info *)
  2924.             xzalloc(sizeof(struct mips_extra_func_info));
  2925.  
  2926.         e->numargs = 0;    /* the kernel thinks otherwise */
  2927.         /* align_longword(sigcontext + SIGFRAME) */
  2928.         e->pdr.frameoffset = 0x150;
  2929.         e->pdr.framereg = SP_REGNUM;
  2930.         e->pdr.pcreg = 31;
  2931.         e->pdr.regmask = -2;
  2932.         e->pdr.regoffset = -(41 * sizeof(int));
  2933.         e->pdr.fregmask = -1;
  2934.         e->pdr.fregoffset = -(37 * sizeof(int));
  2935.         e->pdr.isym = (long)s;
  2936.  
  2937.         current_objfile = st->objfile; /* Keep new_symbol happy */
  2938.         s = new_symbol(".gdbinfo.");
  2939.         SYMBOL_VALUE(s) = (int) e;
  2940.         SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
  2941.         SYMBOL_CLASS(s) = LOC_CONST;
  2942.         SYMBOL_TYPE(s) = builtin_type_void;
  2943.         current_objfile = NULL;
  2944.     }
  2945.  
  2946.     BLOCK_SYM(b,BLOCK_NSYMS(b)++) = s;
  2947. }
  2948.  
  2949. /* Initialization */
  2950.  
  2951. static struct sym_fns ecoff_sym_fns =
  2952. {
  2953.   "ecoff",        /* sym_name: name or name prefix of BFD target type */
  2954.   5,            /* sym_namelen: number of significant sym_name chars */
  2955.   mipscoff_new_init,    /* sym_new_init: init anything gbl to entire symtab */
  2956.   mipscoff_symfile_init,/* sym_init: read initial info, setup for sym_read() */
  2957.   mipscoff_symfile_read,/* sym_read: read a symbol file into symtab */
  2958.   mipscoff_symfile_finish,/* sym_finish: finished with file, cleanup */
  2959.   NULL            /* next: pointer to next struct sym_fns */
  2960. };
  2961.  
  2962.  
  2963. void
  2964. _initialize_mipsread ()
  2965. {
  2966.     add_symtab_fns (&ecoff_sym_fns);
  2967.  
  2968.     /* Missing basic types */
  2969.     builtin_type_string =
  2970.         init_type (TYPE_CODE_PASCAL_ARRAY,
  2971.                1, 0, "string",
  2972.                (struct objfile *) NULL);
  2973.     builtin_type_complex =
  2974.         init_type(TYPE_CODE_FLT,
  2975.               2 * sizeof(float), 0, "complex",
  2976.               (struct objfile *) NULL);
  2977.     builtin_type_double_complex =
  2978.         init_type(TYPE_CODE_FLT,
  2979.               2 * sizeof(double), 0, "double_complex",
  2980.               (struct objfile *) NULL);
  2981.     builtin_type_fixed_dec =
  2982.         init_type(TYPE_CODE_INT, sizeof(int),
  2983.               0, "fixed_decimal",
  2984.               (struct objfile *) NULL);
  2985.     builtin_type_float_dec =
  2986.         init_type(TYPE_CODE_FLT, sizeof(double),
  2987.               0, "floating_decimal",
  2988.               (struct objfile *) NULL);
  2989. }
  2990.